This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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

 
Ranch Hand
Posts: 101
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?
 
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
e.g.
 
Mark Moge
Ranch Hand
Posts: 101
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
Netbeans IDE Ubuntu Java
  • 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: 101
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
Netbeans IDE Ubuntu Java
  • 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: 101
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.

 
Just let me do the talking. Ahem ... so ... you see ... we have this tiny ad...
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic