Accessing directory inside a Jar

  • Josef Sauter
    Josef Sauter


    I have the following problem and i dont know how to get around it.
    One of the libraries i am using for my project, requires me to set the directory to the native libraries. Since I just want to have one jar! I want to have this libraries inside that Jar. But I have to set that directory, some thing normally like this:

        setNativeLibrariesDirectory(new File("some/path/to/the/directory")
    I have been trying to use all sorts of stuff, without luck. One of the things i've tried is to use this.


    but the URL is the following jar:file:/some/path/to/project/dist/project-linux.jar!/binlib

    What can i do?
    If anybody helps me i would really really really apreciate it.

    Thank You very much
    Josef Sauter

  • P. Simon Tuffs
    P. Simon Tuffs

    Hi Josef: you can use the One-Jar-Expand and One-Jar-Expand-Dir manifest attributes in your one-jar archive to cause the JarClassLoader to expand files into the filesystem, at a known location.  This is partially documented in the FAQ: and fully documented in the source code load(String) method.

    Make sure the target (temporary) directory is writable.

    Good luck.

  • Josef Sauter
    Josef Sauter

    Hi Simon,
    First of all thanks for your replay. I've been watching the code of your class loader, and i have learned a couple of things. the expansion wroked and I love your project. In case you need help with the documentation, tutorials or that kind of stuff, just let me know, I would be pleased to help!

    Thanks a lot 
    Josef Sauter