Our product is a stand-alone OS X desktop application written in Java. We include an embedded JRE to run our software.
The rules for JRE startup seem to put any JAR files in /usr/lib/java
, /Library/Java/Extensions
, and ~/Library/Java/Extensions
on the classpath BEFORE the libraries we explicitly include on the classpath.
If a user has any JAR files in any of the Java extension mechanism folders, then those JAR files get added to our classpath. A recent support incident arose because a customer had an older version of a critical third-party library in /usr/lib/java
- this was causing our software to crash unexpectedly at startup.
I've been unable to determine how I can disable this extension mechanism when invoking the JRE embedded in our app. How can I do this?
─────────
NOTE: it seems that this extension mechanism is deprecated and will eventually be removed: https://blogs.oracle.com/java-platform-group/entry/planning_safe_removal_of_under)
You can override the "java.ext.dirs"
JVM argument to point to some application directory.
I tested overriding JVM Argument and it works fine.
$ ls /Library/Java/Extensions
extentionstest.jar
$
$java ExtentionTest
Main method executed fine.
$
$ java -Djava.ext.dirs=/home/pratapk/work/ ExtentionTest
Error: Could not find or load main class ExtentionTest
$
And the ExtentionTest
class is built into extentionstest.jar
and copied at /Library/Java/Extensions
public class ExtentionTest {
public static void main(String args[] ) {
System.out.println("Main method executed fine.");
}
}
java.ext.dirs
supports multiple directory as colon separated. In your case the JRE is included along with your app, It is much easier for you include the path of lib/ext
while not including "/Library/Java/Extensions"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With