generate jar without dependencies

时间:2016-05-11 11:31:48

标签: java jar java-compiler-api javacompiler

I am generating a jar inside a java program by using the jdk system-compiler.

I have some class files which I add into a jar:

JarOutputStream target = new JarOutputStream(jarStream, manifest);
addClassFilesToJar(new File(classDirectory), target);

I have some dependencies which I added into the manifest as:

lib/dependency1.jar
lib/dependency2.jar
...

Now the jar looks up in a sub-folder lib for the dependencies.

The jar itself should not be a runnable standalone jar. I want to include the jar in a project where all the dependencies are already present.

MyApp/              <-- Root folder of project
MyApp/MyJar         <-- folder for the generated jar lies
MyApp/dependencies  <-- folder for dependencies from MyApp and MyJar 

So what do I have to do, to generate the jar in a manner that the classpath argument itself given to the jvm will handle the dependencies? (wanted solution)

Is it possible or do I have to create the manifest so that it points to the MyApp/dependencies folder? (not wanted solution)

0 个答案:

没有答案