• 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 ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Reference another jar file's contents from an Executable Jar

 
Greenhorn
Posts: 4
1
  • Mark post as helpful
  • send pies
  • 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: 10302
217
  • Mark post as helpful
  • send pies
  • 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
  • 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: 10302
217
  • Mark post as helpful
  • send pies
  • 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
  • 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: 10302
217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad you got it to work, have a cow for getting back to us
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!