每当有人部署应用程序时问题都是一个问题:在部署项目之后,java在哪里寻找库(jars和dll)?
祝你好运, 斯蒂芬
答案 0 :(得分:1)
正如其他答案所暗示的那样,它看起来有几个不同的地方。您可以使用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;
}
答案 1 :(得分:0)
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
**
答案 2 :(得分:0)
在classpath上。
在应用程序服务器上,通常已经设置了很多路径。您通常可以检查启动日志或记录以下属性的值以确定其查找位置:
System.getProperty("java.class.path")