• 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Jar Using Other Jar

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I want to know is it possible to use a Single jar file which contains classes that uses other jar that helps for DB connection, logging. And the other jar should be in the same single jar. Or there might be a way if i extract all the jar into a single directory and append all the manifest info of all jars into single manifest file.

Thanks
 
Rancher
Posts: 43024
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The standard classloader can't handle jar files inside of other jar files. But if you ship several jar files, then the manifest of the one containing the main class can reference the other jar files. See http://java.sun.com/docs/books/tutorial/deployment/jar/manifestindex.html particularly "Adding Classes to the JAR File's Classpath".
 
robin singal
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

First i would explore the possibilities of manifest file then i would post weather I got it worked

Thanks
 
robin singal
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what i found useful:

Note : The Class-Path header points to classes or JAR files on the local network, not JAR files within the JAR file or classes accessible over internet protocols. To load classes in JAR files within a JAR file into the class path, you must write custom code to load those classes. For example, if MyJar.jar contains another JAR file called MyUtils.jar, you cannot use the Class-Path header in MyJar.jar's manifest to load classes in MyUtils.jar into the class path.



What custom code i have to write ??

Thanks
 
Ulf Dittmer
Rancher
Posts: 43024
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'd need to write a ClassLoader implementation that knows how load classes from jar files inside of jar files. That's not rocket science, but not for the faint of heart (or beginners) either.

Start by using multiple jar files that are referenced from a single manifest, and see if that works for you.
 
author
Posts: 9025
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
whoa!

I don't know about you guys, but this seems like at least an intermediate discussion to me!

off it goes...
 
robin singal
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Start by using multiple jar files that are referenced from a single manifest, and see if that works for you.



ya i have done that, the other jar files were placed outside the executable jar in lib folder and i gave that information in the manifest file. It runs fine.

That's not rocket science, but not for the faint of heart (or beginners) either.



I am not a beginner now as Bert has moved it to intermediate ...
Atleast i can try ,How can i write a classloader implementation ??
From where to start ?

Thanks
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another approach might be using maven with the assembly or shade plugin.

These plugins will build jars with all dependencies included.

Reagrds,
Uli
 
robin singal
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ya I would see to it & would ensure that the thread moves to the expert level.

Thanks
 
reply
    Bookmark Topic Watch Topic
  • New Topic