Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the relation between java.library.path and classpath

I'm looking for a simple explanation of the relation between java.library.path and the classpath. Though I'm hardly a newbie, I have never had to mess with the j.l.p. But we are having problems with a WebSphere MQ application I am involved in and we would like to turn their tracing on. Unfortunately, once I told IBM that we had repackaged the MQ jars so that we could deploy via Maven, they wouldn't even talk to me about the issue unless we loaded the WebSphere MQ jars with java.library.path.

So great, let's redo our whole deployment strategy. I'm okay with biting that bullet, but here is my question:

What is the relation between java.library.path and the classpath? Are classes found on j.l.p visible to the compiler? do you have to specify the j.l.p on the command line of the compiler? Can you specify these classes on both the j.l.p and the classpath? Which takes precedence.

And please don't bum-rap this question for insufficient research. I've of course googled "java.library.path". Gazillions of hits of course. I tried doing an advanced google search restricting the expression to the oracle.com site. Still gazillions of hits. I tried googling both terms. Get a lot of newbie explanations of dubious quality. I've tried searching the java language Specification. No hits.

I want a concise and authoritative explanation. Can someone point me at one?

UPDATE - IBM insists that their MQ trace facility will not work unless I load my application with -Djava.library.path={path to MQ jars} and they won't even support me in spite of having a service contract unless I do it this way. And yet, of course, I have code that references these classes and must compile. This is the motivation behind this question.

like image 552
Steve Cohen Avatar asked Jul 25 '14 20:07

Steve Cohen


People also ask

Is classpath and path the same?

The main difference between PATH and CLASSPATH is that Path is set for java tools in java programs like java and javac, which are used to compile your code. Whereas CLASSPATH is used by System or Application class loader to locate and load compile Java bytecodes stored in the . class file.

What is the use of Path and Classpath in Java?

PATH is used by CMD prompt to find binary files. CLASSPATH is used by the compiler and JVM to find library files.

What is the difference between Path and Classpath variables?

Path is used define where the system can find the executables(.exe) files and classpath is used to specify the location .

What is the Java library path?

java. library. path is a System property, which is used by Java programming language, mostly JVM, to search native libraries, required by a project. Similar to PATH and Classpath environment variable, java.


1 Answers

What is the relation between java.library.path and the classpath?

None, the only thing they have in common is that they are both paths.

Are classes found on j.l.p visible to the compiler?

No.

do you have to specify the j.l.p on the command line of the compiler?

Never. You only need this at runtime.

Can you specify these classes on both the j.l.p and the classpath?

Only put classes on the class path.

The j.l.p is equivalent to the LD_LIBRARY_PATH and tells the OpenJDK/HotSpot JVM where to find shared native libraries like .DLL or .so not JARS, not classes.

http://examples.javacodegeeks.com/java-basics/java-library-path-what-is-it-and-how-to-use/

like image 54
Peter Lawrey Avatar answered Oct 23 '22 02:10

Peter Lawrey