How can I detect if the program runs in JAR or not?
I'm asking that, because of the loading resources like pictures, templates etc. Inside a JAR file it will be different.
Thank you in advance.
I'm asking that, because of the loading resources like pictures, templates etc. Inside a JAR file it will be different.
No, it won't, if you do it correctly.
This will work exactly the same whether the class is loaded from a directory, a webserver or a JAR file:
ImageIcon icon = new ImageIcon(getClass().getResource("logo.gif"));
Alternatively, use the getResourceAsStream()
method for maximal flexibility.
Examine getClass().getProtectionDomain().getCodeSource().getLocation();
- this'll give you a directory or a jar.
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