LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-05-2004, 10:50 AM   #1
linux_ub
Member
 
Registered: May 2004
Location: NY
Distribution: fedora core 1
Posts: 65

Rep: Reputation: 18
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
 
Old 08-05-2004, 12:22 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 110Reputation: 110
Try the "jar" program.
See: http://java.sun.com/docs/books/tutorial/jar/
 
Old 08-05-2004, 01:03 PM   #3
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.3, Oracle Linux, Mint, Tribblix
Posts: 9,754

Rep: Reputation: 457Reputation: 457Reputation: 457Reputation: 457Reputation: 457
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.
 
Old 08-05-2004, 03:56 PM   #4
linux_ub
Member
 
Registered: May 2004
Location: NY
Distribution: fedora core 1
Posts: 65

Original Poster
Rep: Reputation: 18
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)
 
Old 08-05-2004, 04:39 PM   #5
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.3, Oracle Linux, Mint, Tribblix
Posts: 9,754

Rep: Reputation: 457Reputation: 457Reputation: 457Reputation: 457Reputation: 457
jar tvf file.jar gives you the list of files inside the jar.
See if org/jdom/JDOMException.class is there.
 
Old 08-06-2004, 08:47 AM   #6
linux_ub
Member
 
Registered: May 2004
Location: NY
Distribution: fedora core 1
Posts: 65

Original Poster
Rep: Reputation: 18
no it is not there ... how can i include it in my jar file .... am using eclipse to create my jar file.

thanks
 
Old 08-07-2004, 11:53 AM   #7
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.3, Oracle Linux, Mint, Tribblix
Posts: 9,754

Rep: Reputation: 457Reputation: 457Reputation: 457Reputation: 457Reputation: 457
Perhaps stop using eclipse and use the command line instead ...
 
Old 08-11-2004, 01:40 AM   #8
german
Member
 
Registered: Jul 2003
Location: Toronto, Canada
Distribution: Debian etch, Gentoo
Posts: 312

Rep: Reputation: 30
In eclipse, go File->Export->Jar File (I think)... from there it should be pretty obvious
 
Old 08-12-2004, 08:45 AM   #9
linux_ub
Member
 
Registered: May 2004
Location: NY
Distribution: fedora core 1
Posts: 65

Original Poster
Rep: Reputation: 18
i read after googling tht there can't be any jar files in a jar ... is it true ... ???
 
Old 08-12-2004, 02:01 PM   #10
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.3, Oracle Linux, Mint, Tribblix
Posts: 9,754

Rep: Reputation: 457Reputation: 457Reputation: 457Reputation: 457Reputation: 457
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.
 
Old 08-12-2004, 02:09 PM   #11
linux_ub
Member
 
Registered: May 2004
Location: NY
Distribution: fedora core 1
Posts: 65

Original Poster
Rep: Reputation: 18
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
 
Old 08-12-2004, 02:50 PM   #12
bruce ford
Member
 
Registered: Jul 2004
Location: Munich, Germany
Distribution: Sun Solaris 8, SuSE 9.0
Posts: 43

Rep: Reputation: 15
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
 
Old 08-12-2004, 05:34 PM   #13
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.3, Oracle Linux, Mint, Tribblix
Posts: 9,754

Rep: Reputation: 457Reputation: 457Reputation: 457Reputation: 457Reputation: 457
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
jar files Knowledgements Slackware 12 07-22-2005 04:36 AM
Fedora Core 1 Associating .jar files with java -jar command pymehta Fedora 0 01-13-2005 06:26 AM
Jar files krazibon3 Linux - Newbie 3 08-05-2004 10:42 PM
What do i do with .jar files joeman3429 Fedora 11 07-26-2004 12:00 PM
jar files mlynch147 Programming 2 10-24-2001 08:11 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration