Java Compilation task and classpath option not working -
I was trying to create a class to compile some .java that I will create on runtime, but not me You can get it to work properly.
This is my code
file bin = new file (Args [args.length-1]); System.setProperty ("java.home", "C: \\ Program Files \\ Java \\ jdk1.7.0_60"); JavaCompiler Compiler = Toolpace .getSystemJavaCompiler (); Standard Java File Manager Levelsfile Manager = compiler.getStandardFileManager (empty, null, empty); {StandardJavaFileManager.setLocation (try the standard location. CLASS_OUTPUT, arrays.asList (bin)); } Hold (IOException e) {System.err.println ("invalid bin directory"); E.printStackTrace (); } List & lt; String & gt; Option = New Arreelist & lt; String & gt; (); Options.add ("- Xlint: uncontrolled"); Options.add ("- classpath"); Options.add ("e: \\ ParentProject.jar"); Println (option); Collection Task Compilation Task = Compiler.Titask (blank, standardJW file manager, blank, options, blank, standard_fileManager.GateJavaFileAbjectFormFile (archives)); CompilationTask.call ();
I am trying to compile Son.java which extends a class in ParentProject.jar, but it does not work even using the "-class path" flag Does. However, if I combine the construction path of the compiler project, then it works (and this classpath flag is not required). Is this normal behavior?
And this leads to another problem when I try to use this code in a project running on the Tomcat server, even with a jar in the web-INF / Lib , I can not get it to work
You can add JAR as your square path:
StandardJavaFileManager.setLocation (standard location.CLASS_PATH, arrays.slist (new file ("path / in / ParentProject.jar")));
Comments
Post a Comment