Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Mark Moge
Ranch Hand
Posts: 100
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
e.g.
 
Mark Moge
Ranch Hand
Posts: 100
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After that i have an exception
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 100
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 781
Java Netbeans IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 100
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I can see your point of view and it works. Thanks a lot for solution.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic