A blog about random stuff. Partner sites: Javaforums.net dotNETProgrammers.net PaintLord.net Retardation-foundation.com The blog is supported by contributors,volunteers and our sponsers.
21 Aug 2008 @ 12:09 AM
Java compiler API, compiling made easy
(3 votes, average: 3.33 out of 5)
Loading ...
2,751 views
Before Java 1.6 was released to the public I used the Runtime class (found in java.lang) to call the java compiler (javac.exe) directly to compile a Java file from another Java application, the line of code that i used looks like this
But luckily for me Java 1.6 introduced a handy utility that makes it possible to compile a Java application within a Java application without making direct calls to an external application. To demonstrate that I wrote a HelloWorld Java file and a CompilerConsoleDemo class that compiles the HelloWorld java file.
The output should look like this Compiling:
1 public class HelloWorld {
2 public static void main(String[] args){
3 System.out.println("Hello World");
4 }
5 }
Result(s):
File successfully compiled!
Output:
Hello World
But if an error occurred this will be shown instead
Compiling:
1 public class HelloWorld {
2 public static void main(String[] args){
3 System.out.println("Hello World")
4 }
5 }
It looks like a really powerful utility but I haven't looked into the JavaCompiler class that much myself so there are still things that I need to figure out about the Compiler API to make maximal use it.
[...] will once i have the time to write a readme and license for it. However you can take a look here: Engineeringserver.com | Java compiler API, compiling made easy and here Engineeringserver.com | [ java file copy ] Java folder watching to combine both of my [...]
[...] will once i have the time to write a readme and license for it. However you can take a look here: Engineeringserver.com | Java compiler API, compiling made easy and here Engineeringserver.com | [ java file copy ] Java folder watching to combine both of my [...]