0

Possible Duplicate:
Can you add multiple jars in a jar file and then launch that jar file

I would like to find a way to embed a jar file into an executable jar file so all the utilities required for the program are contained in the jar file.

This URL describes what I want to do, but says it is only possible by writing a custom class loader:

http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html

Even tho that URL is discouraging, I am not giving up.

The specific .jar file that I want to embed is the groovy.jar file.

Specifically, I would like my jar file to look like this:

jar -tf MyProg.jar
META-INF/
META-INF/MANIFEST.MF
lib/groovy-all-1.6.9.jar
MyProg.class

And I would like to execute like this:

java -jar MyProg.jar

Where MyProg.class is a groovy program, and groovy is not installed on the computer that runs java -jar MyProg.jar

I have been successful at exploding the groovy.jar file within the MyProg.jar file, but that is messy.

Does anyone have a custom class loader that does what I want? Does anyone have any other ideas?

Community
  • 1
  • 1
Be Kind To New Users
  • 9,672
  • 13
  • 78
  • 125

2 Answers2

1

If I understand correctly, I think your case is simpler than the one you link to, because it addresses the case where the other jars are outside the caller jar, whereas you want to reference a jar inside your jar.

I use Eclipse, which automatically includes resources, including jars. I simply right-click the relevant package and set the build path. Other IDEs are probably capable of the same thing.

If you don't use an IDE (?!), the JAR file format is nothing more than a zip file. You can use any zip archiver to create the JAR file, as long as you ensure that the MANIFEST file is first.

Allen Z.
  • 1,560
  • 1
  • 11
  • 19
0

You can't bundle different jars together easily as the class path entry of the manifest file only references jars outside of your jar itself.

Some tools may help you to change your jar and change its class loading mechanism. See why your question is closed.

Snicolas
  • 37,840
  • 15
  • 114
  • 173