File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Ant, Maven and Other Build Tools and the fly likes Ant - How to create a runnable jar of jars and classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Ant - How to create a runnable jar of jars and classes" Watch "Ant - How to create a runnable jar of jars and classes" New topic
Author

Ant - How to create a runnable jar of jars and classes

Mark Moge
Ranch Hand

Joined: Mar 14, 2009
Posts: 96

I am trying to create a runnable jar of jars and classes.
In my build.xml file I have

After creating new jar it consist of *.class and *.jar files and if I want to run it I have an error

I saw that Eclipse adds to the manifest file

and the jar has classes from org.eclipse.jdt.internal.jarinjarloader package

If I add classes from org.eclipse.jdt.internal.jarinjarloader and update Manifest as above I can run my jar (but it's not a clean job). Can you tell me how can I do it without using classes from eclipse package?


SCJP6 | http://programmerutilities.blogspot.com/
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

e.g.


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Mark Moge
Ranch Hand

Joined: Mar 14, 2009
Posts: 96

After that i have an exception
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Run
jar -tf your-jar-file.jar
and make sure that the list contains the class com.portal.pcm.EBufException in the directory com/portal/pcm . If it doesn't then you need to modify the 'include' set to make sure it gets included.
Mark Moge
Ranch Hand

Joined: Mar 14, 2009
Posts: 96

James Sabre wrote:Run
jar -tf your-jar-file.jar
and make sure that the list contains the class com.portal.pcm.EBufException in the directory com/portal/pcm . If it doesn't then you need to modify the 'include' set to make sure it gets included.

com.portal.pcm.EBufException is part of pcm.jar and this jar is included.

As I sad If I add to my jar *class files from eclipse and modify manifest as in first post everything works. The exception tells something about URLClassLoader and two classes from eclipse have Loader in a name.
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Since you are trying to avoid using the Eclipse jar-in-jar class loader you cannot put the jars your main jar needs in the main jar. They need to be external to your main jar and, as I illustrated in my first post, you must define a Class-Path entry in your manifest. The entry is a list of jars separated by spaces.

Assuming that your dependency jar are external to the main jar and in the directory 'lib' relative to your main jar then your Class-Path entry will be

Class-Path : lib/ajar.jar lib/bjar.jar lib/cjar.jar

Obviously replacing ajar.jar bjar.jar etc with names of the jars.
Mark Moge
Ranch Hand

Joined: Mar 14, 2009
Posts: 96

Ok, I can see your point of view and it works. Thanks a lot for solution.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ant - How to create a runnable jar of jars and classes