DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > SKP's Java/Java EE Gotchas: JAR File Dependencies

SKP's Java/Java EE Gotchas: JAR File Dependencies

If you plan on referring to JARs wrapped up in different JARs, don't do i through the Manifest's Class-Path. Move them to the same level or directory.

Sumith Puri user avatar by
Sumith Puri
·
Jan. 19, 17 · Java Zone · Tutorial
Like (1)
Save
Tweet
6.53K Views

Join the DZone community and get the full member experience.

Join For Free

You might find yourself running into a problem where you want to refer to a JAR inside another JAR. Many developers would assume that by adding it to the Class-Path within MANIFEST.MF, it should be included in the classpath. But that doesn't work.

Test.jar:

|  /META-INF

|  |     MANIFEST.MF

|  |        Main-Class: com.persistent.accelerite.main.AppLauncher

|  |        Class-Path: commons-logging.jar

|  /com/persistent/accelerite/main

|  |     AppLauncher.class

|  commons-logging.jar


This may be very surprising or something that shies away from your strongest belief/intuition, but it will not work! You have to extract the required JARs and put them at the same level or same directory as the directory where test.jar is located. In the above class, trying to use jar:file:jarname.jar!/commons-logging.jar in the Class-Path will also not work. The only other way to achieve this is to write custom class loaders.

This is as per the Java Archive Specification from the official Oracle documentation:

Class-Path:

The value of this attribute specifies the relative URLs of the extensions or libraries that this application or extension needs. URLs are separated by one or more spaces. The application or extension class loader uses the value of this attribute to construct its internal search path.

JAR (file format)

Published at DZone with permission of Sumith Puri. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • The Power of Enum: Make Your Code More Readable and Efficient [Video]
  • Terraform Controller: Cloud Resource Self-Service
  • Develop With Oracle Transactional Event Queues
  • How to Classify NSFW (Not Safe for Work) Imagery with AI Content Moderation using Java

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo