Gobliins
Gobliins

Reputation: 4026

javax.tools compiler generate jar

currently i compile my java sourcefiles with:

ArrayList<String> optionList = new ArrayList<String>();
String testpath = System.getProperty("java.class.path") + convertJarFilesToClassPath(getJarFiles());
optionList.addAll(Arrays.asList("-classpath", testpath));
optionList.addAll(Arrays.asList("-d", this.outputDir+"\\bin"));

ArrayList<File> files1 =  getSourceFiles();
Iterable<? extends JavaFileObject> compilationUnits1 = fileManager.getJavaFileObjectsFromFiles(files1);
JavaCompiler.CompilationTask task = compiler.getTask(null ,fileManager ,null , optionList, null, compilationUnits );
boolean compiled = task.call();

Then i get my .class files correctly compiled, but i would like to have also a jar file generated. I am not familiar with the JavaCompiler, i use jdk 7.

What do i have to do, to tell the javax.tools.JavaCompiler to generate a jar file?

Upvotes: 0

Views: 773

Answers (1)

wero
wero

Reputation: 33010

javax.tools.JavaCompiler and javac only compile classes and generate .class files.

To bundle the compiled classes into a JAR file you can use JarOutputStream. Here is a tutorial.

Upvotes: 2

Related Questions