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

Jar in a Jar

 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a jar file (project.jar) with the following content

  • com is the root for all my classes
  • META-INF the manifest file directory
  • thirdparty.jar is a external jar file used by my classes


  • I have an entry in the MANIFEST.MF file as follows
    Class-Path: thirdparty.jar

    Now when I use project.jar in another project
    I get


    where javax/xml/bind/JAXBException is a class in the thirdparty.jar file

    Do you have any idea what went wrong
     
    Bartender
    Posts: 10336
    Hibernate Eclipse IDE Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Jars inside jars are not on the classpath. Your manifest entry specifies a jar called thirdparty.jar that should be deployed with your project jar, not in it.
     
    Ranch Hand
    Posts: 1970
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    The system class loader does not understand Jars in Jars. It will find a second Jar in the same directory, if the first Jar's manifest lists that Jar.

    If you really need to be able to load classes from Jars in Jars, you could write your own class loader to achieve that. Writing class loaders is not a beginner task, but it's not too hard. There may be ready-made code on the Web.

    Another approach is to unjar your third-party Jar, then include the resulting files in your Jar. Be sure to comply with any licenses, if considering this.
    [ January 07, 2008: Message edited by: Peter Chase ]
     
    Java Cowboy
    Posts: 16084
    88
    Android Scala IntelliJ IDE Spring Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    As the others have said, nested JAR files are not supported by Java. If you want to deliver your application in a single JAR file, then have a look at this tool: http://one-jar.sourceforge.net/
     
    Attractive, successful people love this tiny ad:
    Free, earth friendly heat - from the CodeRanch trailboss
    https://www.kickstarter.com/projects/paulwheaton/free-heat
    reply
      Bookmark Topic Watch Topic
    • New Topic