Add java.library.path to java manifest

2019-05-22 02:56发布

问题:

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.

回答1:

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



回答2:

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.