javamacosclasspath

What is the role of /Library/Java/Extensions - is it safe to add or remove classes from there?


What role does the directory /Library/Java/Extensions play in regards to Mac OSX's Java framework?

Is it automatically updated by Apple's Java updates, and is it safe to modify what the directory holds without affecting the stability of the JVM or Java applications?

Edit: Specifically, if an existing jar in Extensions is causing a conflict, what are the implications of removing the class from the Extensions directory?


Solution

  • Java 9+

    The Java Extension mechanism was removed in Java 9 and later.

    For details, see: JEP 220: Modular Run-Time Images

    Java 8 and earlier

    Take a look at Java Extensions section of Overview of Java for OS X page of Java Development Guide for Mac.

    Java can be extended by adding custom.jar, .zip, and .class files, as well as native JNI libraries, into an extensions directory. In OS X, put your extensions in /Library/Java/Extensions/. Java automatically looks in this directory as it is starting up the Java Virtual Machine.

    Putting extensions in /Library/Java/Extensions/ loads those extensions for every user on that particular computer. It is preferable to limit which users can use certain extensions by putting them in the ~/Library/Java/Extensions/ directory inside the appropriate users’ home directories. By default, that folder does not exist, so you may need to make it.Try to include all of your dependent libraries in your application rather than relying on the Java Extensions directory, because its contents are unversioned and cannot accommodate for multiple versions of the same library.