Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable Java extension mechanism

Tags:

java

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)

like image 578
Steve McLeod Avatar asked May 24 '15 00:05

Steve McLeod


1 Answers

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"

like image 112
Pratap Koritala Avatar answered Oct 10 '22 20:10

Pratap Koritala