问题描述
|
这个问题在有人部署应用程序时是一个问题:项目部署后,java在哪里寻找库(jar和dll)?
最好的祝福,
斯特凡
解决方法
在其classpath上。
在应用程序服务器上,通常已经设置了很多路径。通常,您可以检查启动日志或记录以下属性的值以确定其外观:
System.getProperty(\"java.class.path\")
,正如其他答案所建议的,它看起来有几个不同的地方。您可以使用System.getProperty(\"java.library.path\")
或System.getProperty(\"java.class.path\")
查看实际路径。
我下面的代码也很有用。您可以使用它在运行时向搜索到的库路径添加路径。
/**
* Allows you to add a path to the library path during runtime
* @param dllLocation The path you would like to add
* @return True if the operation completed successfully,false otherwise
*/
public boolean addDllLocationToPath(final String dllLocation)
{
//our return value
boolean retVal = false;
try
{
System.setProperty(\"java.library.path\",System.getProperty(\"java.library.path\") + \";\" + dllLocation);
//get the sys path field
Field fieldSysPath = ClassLoader.class.getDeclaredField(\"sys_paths\");
fieldSysPath.setAccessible(true);
fieldSysPath.set(null,null);
retVal = true;
}
catch (Exception e)
{
System.err.println(\"Could not modify path\");
}
return retVal;
}
,http://en.wikipedia.org/wiki/Classpath_%28Java%29
**虚拟机按以下顺序搜索和加载类:
bootstrap classes: the classes that are fundamental to the Java Platform (comprising the public classes of the Java Class Library,and the private classes that are necessary for this library to be functional).
extension classes: packages that are in the extension directory of the JRE or JDK,jre/lib/ext/
user-defined packages and libraries
**