How to shorten classpath?

What are the repercussions of using "java.ext.dirs" together with "-classpath"?

  • "java.ext.dirs" appear to work just like -classpath.  I know of an application that uses them together in including libs. An observation is that you should not include the same jar with java.ext.dirs and -classpath. What could be the reason behind this?

  • Answer:

    The problem is one of versions. With CLASSPATH, you specify exactly what files are going to be included. With java.ext.dirs, it includes everything in the directory. There is some set of rules by which the classloader decides which jar files reference which other jar files. If you have the same file in both places, it's very easy for the two to get out of synch, and you can end up with incompatibilities leading to crashes. The java.ext.dirs mechanism makes it easy to accidentally include multiple versions of the same file, since it takes everything in the directory. Generally, you use CLASSPATH for your program itself, and you use java.ext.dirs for plugins and extensions that are discovered from and loaded by your program. You can use java.ext.dirs alone, and it can be easier, but on a large-scale production environment it gets fraught.

Joshua Engel at Quora Visit the source

Was this solution helpful to you?

Other answers

In addition, another complication is that java.ext.dirs uses a different ClassLoader from the classpath set through -classpath: http://docs.oracle.com/javase/tutorial/ext/basics/load.html This gets confusing especially if the code in the jars - especially libraries - do explicit classloading.

Miguel Paraz

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.