I'm developing an application that uses a library that loads a configuration file as:
InputStream in = getClass().getResourceAsStream(resource);
My application in then packed in a .jar
file. If resource
is inside the .jar
file, I can specify the path as "/relative/path/to/resource/resource"
.
I'd like to know if is it possible to find the resource if it is outside the .jar
file, and in this case, how would I specify the path.
(Assuming my application's jar is in app/
and the resource is in app/config
).
The program uses a 3rd party library. The library uses the resource as a configuration file.
I also want to tweak the configuration file without having to unzip/zip the jar file all the time.
jar ) contain your executable classes and resource files. A jar can also contain other jar files, which is useful when your program needs some library which is packaged in a jar.
A JAR file may contain a manifest file, that is located at META-INF/MANIFEST.
In general, yes it can. Technically, the class's ClassLoader
is used to locate the resource named in the parameter (see Javadoc here). If you're not using a special ClassLoader
then you'll get the bootstrap class loader, which searches the class path. So, if you have directories or other jar files on the classpath, they will be searched.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With