Cui Pengfei 崔鹏飞
Cui Pengfei 崔鹏飞

Reputation: 8305

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

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?

Upvotes: -1

Views: 85

Answers (1)

kan
kan

Reputation: 28981

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.

Upvotes: 0

Related Questions