What is the relation between java.library.path and classpath
Asked Answered
R

1

12

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.

Rigatoni answered 25/7, 2014 at 20:31 Comment(0)
S
16

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/

Spoiler answered 25/7, 2014 at 20:37 Comment(2)
Thanks for the link, Peter. I think the MQ jars, at least some of them, ARE native code (the MQ classes for java are a wrapper around C), so this might be appropriate. And yet I've been running them from the classpath for years, with no issues, until I have to turn this trace facility on.Rigatoni
You can't load a JAR as a native library, the OS just won't support that. You can put a native library inside a JAR but the ONLY way to load it is to extract it to the filesystem, and then load it, usually explicitly with System.load(). It is possible the MQ libraries use teh java.library.path in a manner for which it was not intended. i.e. a library can parse and use a property for whatever it likes.Spoiler

© 2022 - 2024 — McMap. All rights reserved.