java中的库查找路径

java中的库查找路径,java,Java,每当有人在部署应用程序时都会遇到一个问题:在部署项目后,java在哪里寻找it库(JAR和DLL) 致以最良好的祝愿, 斯特凡 **虚拟机按以下顺序搜索和加载类: 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 nece

每当有人在部署应用程序时都会遇到一个问题:在部署项目后,java在哪里寻找it库(JAR和DLL)

致以最良好的祝愿, 斯特凡

**虚拟机按以下顺序搜索和加载类:

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
**

**虚拟机按以下顺序搜索和加载类:

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
**在其上

在应用服务器上,通常已经设置了相当多的路径。您通常可以检查启动日志或记录以下属性的值,以确定其查找位置:

System.getProperty("java.class.path")
在其上

在应用服务器上,通常已经设置了相当多的路径。您通常可以检查启动日志或记录以下属性的值,以确定其查找位置:

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;
    }

正如其他答案所暗示的,它看起来有几个不同的地方。您可以使用
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;
    }

请说得更具体一些:什么是项目,什么是部署,这两个问题都与您的问题有关!不,这个问题应该以通用的方式回答,这适用于99%的已开发应用程序!更准确地说:在J2EE上下文中进行项目和部署不同于在简单Java应用程序或小程序中进行同样的操作。project可以是一个与IDE相关的术语(比如:eclipseproject),但我真的希望,所有这些项目都共享一个模式,即如何部署它们的库!或者至少有一种方法可以让他们找到他们的库……在引擎盖下,是的。java虚拟机有一个列出路径和库的类路径字符串,
ClassLoader
可以使用其他机制在路径上的目录之外定位类文件。从用户/开发人员的角度来看,模式是由目标环境(applet、可执行jar、应用服务器等)设置的。请更具体地说:什么是项目,什么是部署,这两者都是在您的问题的上下文中!不,这个问题应该以通用的方式回答,这适用于99%的已开发应用程序!更准确地说:在J2EE上下文中进行项目和部署不同于在简单Java应用程序或小程序中进行同样的操作。project可以是一个与IDE相关的术语(比如:eclipseproject),但我真的希望,所有这些项目都共享一个模式,即如何部署它们的库!或者至少有一种方法可以让他们找到他们的库……在引擎盖下,是的。java虚拟机有一个列出路径和库的类路径字符串,
ClassLoader
可以使用其他机制在路径上的目录之外定位类文件。从用户/开发人员的角度来看,模式是由目标环境(applet、可执行jar、应用服务器等)设置的。。这对于本机库是不正确的。。。这对于本机库是不正确的。