Reputation: 245
Suppose there is a Java file that exists in an external folder. Can I write a Java program which will generate a .class file of that Java file and place the .class file in the same external folder?
Upvotes: 4
Views: 2930
Reputation: 7517
It's in here: java.lang.Compiler
.
This class has the method compileClass(Class class)
and compileClasses(String names)
Upvotes: 0
Reputation: 23349
yes , you can do it using java compiler
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(null,null,null);
Check this for further details
Upvotes: 1
Reputation: 67138
The easiest way (for me) is to include tools.jar
and to invoke the com.sun.tools.javac.Main.compile(
) function.
Upvotes: 3