0

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?

Gobliins
  • 3,848
  • 16
  • 67
  • 122

1 Answers1

2

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.

Community
  • 1
  • 1
wero
  • 32,544
  • 3
  • 59
  • 84