Is there any way to programatically generate class files from .java files present in a folder. There are examples using JavaCompiler.CompilationTask for compiling single java files.But i need to to generate class file from multiple couples .java codes(generated from JAXB gen).
-
possible duplicate of Using Java Compiler API to compile multiple java filesVince– Vince2014-11-18 18:53:55 +00:00Commented Nov 18, 2014 at 18:53
-
Already tried...not working..throwing this exception: Exception in thread "main" java.lang.IllegalArgumentException: All compilation units must be of SOURCE kind at com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:183) at com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:68) at MyGrp.com.myArtifact.Main.compile(Main.java:154) at MyGrp.com.myArtifact.Main.main(Main.java:121)soumitra chatterjee– soumitra chatterjee2014-11-18 18:58:05 +00:00Commented Nov 18, 2014 at 18:58
-
Can't do much with that stacktrace if you don't show code. Edit a MVCE into your question so we can see how you are attempting to do it. Also, edit in that the duplicate doesn't help because (enter reason here; in your case, exception is thrown, edit the stacktrace into your question as well)Vince– Vince2014-11-18 19:02:04 +00:00Commented Nov 18, 2014 at 19:02
Add a comment
|
1 Answer
Use Runtime.getRuntime().exec("javac ...");
2 Comments
soumitra chatterjee
There are multiple .java files...compilation fails if the parent class is first compiled instead of child class....They .java files are from jaxb generated...
ControlAltDel
you can fix this if you make sure all your compiled classes are contained in the classpath