问题
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.
回答1:
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/
来源:https://stackoverflow.com/questions/24964012/what-is-the-relation-between-java-library-path-and-classpath