Link to home
Start Free TrialLog in
Avatar of SaltyDawg
SaltyDawgFlag for United States of America

asked on

Add Class file to existing Jar File

I have an existing Jar File:
chop_saw.jar

With the following directories and files:
Ebtron
-mechanicalFunctions.class
-EbtronUser.class
-ebtronModel.class
-chopSaw.class
-chopSaw$Display.class
-chopSaw$3.class
-chopSaw$2.class
-chopSaw$1.class

META-INF
-MANIFEST.MF
"Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.2
Created-By: 1.5.0_04-b05 (Sun Microsystems Inc.)
Main-Class: Ebtron.chopSaw
X-COMMENT: Main-Class will be added automatically by build"


Now my question, is it possible to replace one of the class files? I updated "mechanicalFunctions.class". Can I add the new "mechanicalFunctions.class" file and replace the existing one without changing any of the other files. Add would the jar file still work as a clickable executable as before?

Thankx
Avatar of MicheleMarcon
MicheleMarcon
Flag of Italy image

The .jar file are basically zipped file

So:
Unzip the jar in a folder.

Replace the .class file you want

Zip the folder to a .jar file

I already did that.

With Linux, you would do this:

unzip chop_saw.jar
cp mechanicalFunctions.class Ebtron
zip chop_saw.jar Ebtron
Avatar of SaltyDawg

ASKER

If I unzip the file, then replace the class, how do I create a new jar file? Is there an application that creates one. I cannot do it using WinZip or WinRar.
ASKER CERTIFIED SOLUTION
Avatar of Dejan Pažin
Dejan Pažin
Flag of Austria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
How do I run jar.exe, whenever I try to open it, it closes immediatley
Command for updating a jar is..

jar -uvf chop_saw.jar Ebtron/mechanicalFunctions.class
>> How do I run jar.exe, whenever I try to open it, it closes immediatley

How did you make the jar.. ?
The jar was originally created by someone else
I used "jar -uvf chop_saw.jar Ebtron/mechanicalFunctions.class" but got an error

Exception in thread "main" java.lang.NoClassDefFoundError: jar
I used it in the command prompt is that right?
Try giving complete path to jar

C:\java\bin\jar -uvf chop_saw.jar Ebtron/mechanicalFunctions.class
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial