-1

Is it possible to create or modify files inside jar and if it is how to accomplish that?

user1610362
  • 637
  • 2
  • 9
  • 26

4 Answers4

1

One possible solution is to unzip the jar, modify it and zip it back up.

NOTE: You can extract it with a utility like 7-zip or WinRar.

eboix
  • 5,113
  • 1
  • 27
  • 38
1

You can use jar command if you would like to do it through command prompt (or) you may use winzip (or) winrar tools.

Example:

jar uf foo.jar -C classes . -C bin xyz.class

kosa
  • 65,990
  • 13
  • 130
  • 167
0

Ok here are two ways to do this:

  1. Use your favorite zip application, unzip it, change the files and zip it again.

  2. Use a zip library like Zip4J and do the same in your java application.

tbraun89
  • 2,246
  • 3
  • 25
  • 44
0

In a word, yes its possible and you have several options:

  1. Modify the existing jar file. Do this by extracting the jar file (use whatever extractor you need to), modify the file you want (decompile if you don't have the source) and then repackage the jar.

  2. If you don't want to go thru the trouble of changing the jar, you want to copy the existing class file (again decompile if you don't have the source), make the changes you want, compile it and make sure your class file is ahead of the jar in your CLASSPATH. That way when your VM does its classloading, it'll get your modified class first and ignore the one in the jar.

Michael
  • 2,624
  • 2
  • 19
  • 16