Is it possible to override a file that is loaded by getResourceAsStream when running a jar?

53 Views Asked by At

A jar loads a file that is packaged inside the jar itself by using getResourceAsStream.

Is it possible to replace/override that file when running java -jar without modifying the jar itself?

1

There are 1 best solutions below

1
kan On

A jar file just an archive. You could update it with a jar --update tool, which is a part of jdk. It may not work if the jar is signed.

Alternatively you could look into (using the jar tool) the jar-file to figure out what is a main class (find Main-Class: in the META-INF/MANIFEST.MF). Then run the jar file specifying classpath explicitly java -classpath path-with-your-file:theApp.jar.