creating jar files
Hey
i am trying to create my own library in java the directory structure is something like Code:
org/company/crypto - org.company.cryto - org.company.util - org.company.gui i wanna create a jar file tht will incorporate all my packages and give me a single jar file which i can include in my projects and use them. could neone give me ne leads how to do this thanks Note: i am using eclipse as my ide |
Try the "jar" program.
See: http://java.sun.com/docs/books/tutorial/jar/ |
I'm sure eclipse can do it by itself, but if you want to do it on the command line:
jar cvf mylib.jar org/company/crypto org/company/util org/company/gui or better, if the "org" directory only contains your 3 packages: jar cvf mylib.jar org As your see, jar syntax is equivalent to the one used by tar. |
i was able manage creating the jar of the library ... but am unable to it for my main application.
in the classpath in eclipse i have included two jars ... 1. my library and Jdom i created the jar for my main application but it gives me the following error Code:
java.lang.NoClassDefFoundError: org/jdom/JDOMException |
jar tvf file.jar gives you the list of files inside the jar.
See if org/jdom/JDOMException.class is there. |
no it is not there ... how can i include it in my jar file .... am using eclipse to create my jar file.
thanks |
Perhaps stop using eclipse and use the command line instead ...
|
In eclipse, go File->Export->Jar File (I think)... from there it should be pretty obvious
|
i read after googling tht there can't be any jar files in a jar ... is it true ... ???
|
One can put a zip file into a zip file.
A jar file is essentially a zip file, so I see no technical reason avoiding this. However, putting such a jar file in the java classpath wouldn't allow, at least without any trick, to have the JVM able to access classes in the embedded jar. |
yup ... tht was my problem ... i was able to jar it
for example i had the directory lib in my project tht had all external jars and i put in classpath ... lib/jdom.jar the jar was formed and i could see the contents ... but while execting it gave an error ... JDOM not found ne leads to overcome this problem thanks |
hi,
jars containing the all you need to run your program is clearly not what the java designers had in mind. you should simply run your program with all needed external libs in the classpath, e.g. from the commandline: java -cp your.jar:jdom.jar YourClass if this is too annoying to type, put it in a shell script. if you REALLY want to have the whole world in a single jar, extract all the needed jars in one directory and create your own mega jar from that directory using the commands pointed out in this thread. So long... bruce |
You can also put a file named mainClass in the jar root, just containing the main method to start and run it with:
java -jar myApp.jar |
All times are GMT -5. The time now is 11:43 AM. |