• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reference another jar file's contents from an Executable Jar

 
Greenhorn
Posts: 4
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

Simplifying the problem, I have Maven building an executable JAR, with its dependencies being loaded into target/lib

target
- lib
- executable-1.0.jar

Now, let's say I want to reference a DAT file located within a token.jar file that isn't added to the lib directory during the build, but instead whoever is running it would copy their token.jar into the lib directory. How can I add "lib/token.jar" to the Class Path of the executable JAR if the file doesn't exist during build?
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should add a dependency on token.jar, and set its scope to runtime.

You can do all of this in the pom.xml.
 
Aaron Troy
Greenhorn
Posts: 4
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:You should add a dependency on token.jar, and set its scope to runtime.

You can do all of this in the pom.xml.



Hi Stephan,

Thanks for replying.

I've tried this approach before, but the Class-Path in the executable jar's MANIFEST.MF still doesn't include "lib/token.jar". So when a user copies theirs into the lib directory, it isn't in the classpath and can't be found.

Relevant parts of pom.xml:



And here's the MANIFEST.MF from the decompiled jar:



Unfortunately, the token.jar isn't available at build time, so I just need it to exist on the class-path so when it IS copied into the 'lib' directory, it is recognized.
 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried runtime instead of system? The use of system is discouraged.

Anyway, it appears that the addClassPath option does not include runtime dependencies, for some unfathomable reason. What a shame.

I think for now the only solution is to manually add a manifestEntries element to your pom.
 
Aaron Troy
Greenhorn
Posts: 4
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, yes!

<manifestEntries> did the trick.

You're a savior. Thank you!

For those hunting, here is the updated build portion of the pom:

 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad you got it to work, have a cow for getting back to us
 
And will you succeed? Yes you will indeed! (98 and 3/4 % guaranteed) - Seuss. tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic