每当有人部署应用程序时都会出现一个问题:项目部署后,java 在哪里寻找它的库(jar 和 dll)?
最诚挚的问候, 斯特凡
最佳答案
正如其他答案所建议的那样,它看起来有几个不同的地方。您可以使用 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;
}
关于java - java中的库查找路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6125812/