3

The java.library.path can be set before or during the execution of a java app (either by setting the global environment variables of the java library path or by using a flag when running the java exec jar). Can it be set inside the manifest file of the java jar, as is done for classes with Class-Path? Sounds like a feature that should be supported, if it does not exist.

EDIT : since as stdunbar mentioned, the manifest file does not support java.library.path mappings, I've added an answer with an alternative solution to using the manifest file.

Rann Lifshitz
  • 4,040
  • 4
  • 22
  • 42

2 Answers2

6

Since java.library.path can not be set using the manifest file, I looked around for an alternative solution. A nice one is setting java.library.path via the actual application code: setting java.library.path programmatically

This solved my deployment issues like a charm (no need for an additional script to manually set the -Djava.library.path).

Note that if a more dynamic solution is required, the added library path can be stored in a configuration file which is read when setting the java.library.path.

EDIT: Updated link, thanks to @uchuugaka

Rann Lifshitz
  • 4,040
  • 4
  • 22
  • 42
  • 1
    I can't express my thanks at how many hours this comment saved me. I use a `lib/` folder for my application (Windows/Linux/Mac) and the native libraries were not loading on OSX. This fixed the bad path (in a 3rd party library) – Daniel B. Chapman Mar 03 '16 at 22:31
  • 1
    link is dead. Wayback Machine to the rescue!! http://web.archive.org/web/20160214203937/http://blog.cedarsoft.com/2010/11/setting-java-library-path-programmatically/ – uchuugaka Apr 03 '18 at 09:27
3

No, this isn't supported by the spec. In general, the java.library.path variable would be very O/S and machine dependent and including it in a Jar file would not make much sense.

stdunbar
  • 16,263
  • 11
  • 31
  • 53