开发者

Library lookup paths in java

开发者 https://www.devze.com 2023-03-08 03:07 出处:网络
the question which is a problem whenev开发者_运维知识库er somebody is deploying an application: where does java look for it libraries (jars and dlls) after a project got deployed?

the question which is a problem whenev开发者_运维知识库er somebody is deploying an application: where does java look for it libraries (jars and dlls) after a project got deployed?

Best regards, Stefan


It looks a couple of different places as the other answers have suggested. You can use the System.getProperty("java.library.path") or System.getProperty("java.class.path") to see the actual paths.

The code below I also found quite useful. You can use it to add at runtime a path to the library paths that get searched.


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


On its classpath.

On application servers there are usually quite a number of paths set up already. You can usually check the startup logs or log the value of the following property to determine where its looking:

System.getProperty("java.class.path")


http://en.wikipedia.org/wiki/Classpath_%28Java%29

**The virtual machine searches for and loads classes in this order:

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

**

0

精彩评论

暂无评论...
验证码 换一张
取 消