-1

I compiled a class file and want to inject it into an existed jar file. I tried but "jar" command is not a good solution, anyone can help on this?

JerryCai
  • 1,623
  • 4
  • 21
  • 36

3 Answers3

6

You want to do it automatically or manually? If manually then a JAR file is like a ZIP file, so you should be able to open it with any ZIP reader. but you have to change the extension first jar to zip.And then you can change your .class file.

OR
This tutorial details how to update a jar file

jar uf jar-file input-file(s)
Sumit Singh
  • 24,095
  • 8
  • 74
  • 100
0

so I think you can decompress the jar, and copy your class file in the directory you compressed. and re compress these files into a new jar file.

user1203650
  • 300
  • 2
  • 3
  • I also thought of this solution, but compare to inject a file to a existed jar, this way is risky. (Consider Manifest file, too big jar file, etc) – JerryCai Aug 30 '12 at 09:36
0

If you want to automate it in a script jar is your best bet. It's installed with the JDK and gets the job done.

If it's a one time operation you might want to use e.g. 7-Zip or another archiving software that can handle the jar file format (which is basically a ZIP).

Dude
  • 583
  • 2
  • 9