tags:

views:

795

answers:

6

I want to update a .class file in the jar with new one. What is the easies way for it, especially in eclipse ?

+4  A: 

Do you want to do it automatically or manually? If manually, a JAR file is really just a ZIP file, so you should be able to open it with any ZIP reader. (You may need to change the extension first.) If you want to update the JAR file automatically via Eclipse, you may want to look into Ant support in Eclipse and look at the zip task.

JasCav
+3  A: 

Jar is an archive, you can replace a file in it by yourself in your favourite file manager (Total Commander for example).

silent
+2  A: 

This tutorial details how to update a jar file

jar uf jar-file input-file(s)

where 'u' means update.

Brian Agnew
A: 

1) you can extract the file into a folder called

jarname.jar

and then replace the file in the folder, handy if you are updating the class a lot while debugging

2) you can extract the jar replace the file then the jar it up again

3) Open the jar with 7 zip and drag and drop your new class in to copy over the old one

Craig Angus
A: 

Simply drag and drop your new class file to the JAR using 7-Zip or Winzip. You can even modify a JAR file that is included in a WAR file using the parent folder icon, and click Ok when 7zip detects that the inside file has been modified

Lastnico
Using WinZip, you have to open it by first starting WinZip, then drag the jar file into the WinZip window.
awe
A: 

An alternative is not to replace the .class file in the jar file. Instead put it into a new jar file and ensure that it appears earlier on your classpath than the original jar file.

Not sure I would recommend this for production software but for development it is quick and easy.

Dave Jefferson