How can I specify dependencies in the manifest file and then to include it into my .jar file?

Posted by Roman on Stack Overflow See other posts from Stack Overflow or by Roman
Published on 2010-04-07T11:52:58Z Indexed on 2010/04/07 12:03 UTC
Read the original article Hit count: 175

Filed under:
|
|
|

I generated .class files by the following command:

javac -cp \directoryName\external.jar myPackageDirectory\First.java myPackageDirectory\Second.java

I needed to use -cp during compilation and name of .jar file of an "external" library (external.jar) to be able to use this library from my code.


Using my .class files I have generated my .jar file in the following way:

jar cfm app.jar manifest.txt myPackageDirectory\*.class

manifest.txt contains just one line:

Main-Class: myPackageName.First

My problem is that I am not sure that I will be able to run my .jar file on other computers. I think so because during the compilation I specified the location of the .jar file of the external library. So, my .class files (included into the .jar file will try to find the .jar file of the external library in a specific directory and there is no guaranty that that the .jar file of the external library will be in the same directory as on the my computer.


I heard that the above problem can be solved by a

usage of a MANIFEST file that I include in my own jar, and which will list dependency locations

but I do not understand how it works. I do need to specify location of the "external.jar" at the compilation stage (otherwise the compiler complains).

© Stack Overflow or respective owner

Related posts about java

Related posts about jar