• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

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

reply
    Bookmark Topic Watch Topic
  • New Topic