0

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).

3
  • possible duplicate of Using Java Compiler API to compile multiple java files Commented 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) Commented 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) Commented Nov 18, 2014 at 19:02

1 Answer 1

0

Use Runtime.getRuntime().exec("javac ...");

Sign up to request clarification or add additional context in comments.

2 Comments

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...
you can fix this if you make sure all your compiled classes are contained in the classpath

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.