Accessing directory inside a Jar

Help
2009-11-21
2013-05-23
  • Josef Sauter
    Josef Sauter
    2009-11-21

    Hi,

    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.

        getClassLoader().getResource("binlib")

    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
    2009-11-25

    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: http://one-jar.sourceforge.net/index.php?page=documents&file=faq and fully documented in the JarClassLoader.java source code load(String) method.

    Make sure the target (temporary) directory is writable.

    Good luck.

     
  • Josef Sauter
    Josef Sauter
    2009-11-29

    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