LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   creating jar files (https://www.linuxquestions.org/questions/programming-9/creating-jar-files-213776/)

linux_ub 08-05-2004 09:50 AM

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/util
org/company/gui

the class files are in the directories crypto, util and gui. in other word my library has 3 packages
- 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

Hko 08-05-2004 11:22 AM

Try the "jar" program.
See: http://java.sun.com/docs/books/tutorial/jar/

jlliagre 08-05-2004 12:03 PM

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.

linux_ub 08-05-2004 02:56 PM

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
        at longitudinal.gui.MainWindow.newItemAction(MainWindow.java:85)
        at longitudinal.gui.MainWindow$2.actionPerformed(MainWindow.java:67)
        at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
        at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknow
n Source)


jlliagre 08-05-2004 03:39 PM

jar tvf file.jar gives you the list of files inside the jar.
See if org/jdom/JDOMException.class is there.

linux_ub 08-06-2004 07:47 AM

no it is not there ... how can i include it in my jar file .... am using eclipse to create my jar file.

thanks

jlliagre 08-07-2004 10:53 AM

Perhaps stop using eclipse and use the command line instead ...

german 08-11-2004 12:40 AM

In eclipse, go File->Export->Jar File (I think)... from there it should be pretty obvious

linux_ub 08-12-2004 07:45 AM

i read after googling tht there can't be any jar files in a jar ... is it true ... ???

jlliagre 08-12-2004 01:01 PM

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.

linux_ub 08-12-2004 01:09 PM

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

bruce ford 08-12-2004 01:50 PM

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

jlliagre 08-12-2004 04:34 PM

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.