Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Jar in a Jar

Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • 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
    Posts: 10336
    Hibernate Eclipse IDE Java
    • Mark post as helpful
    • send pies
    • 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
    • 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
    Android Scala IntelliJ IDE Spring Java
    • Mark post as helpful
    • send pies
    • 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:
    My, my, aren't you a big fella. Here, have a tiny ad:
    Two software engineers solve most of the world's problems in one K&R sized book
      Bookmark Topic Watch Topic
    • New Topic