Link to home
Start Free TrialLog in
Avatar of g46905
g46905

asked on

command to replace a .class file in my jar?

I have my Test.jar file. I would like to replace a .class file in com.sendMail package which is in my Test.jar file. how can I do this using command line argument in my unix environment? Please help.

Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

You can't - you need to create a new jar
Oh wait

jar uf yourjar.jar NewClass.class

would replace the one of the same name
Avatar of g46905
g46905

ASKER

does it need to be jar uf yourjar.jar com.sendMail.NewClass.class ( am I supposed mention the package name along with the class name ) Please suggest.
Yes you would need to specify the full path

jar uf yourjar.jar com/sendMail/NewClass.class
Avatar of g46905

ASKER

Below is what I tried  and for some reason, it doesn't work...can you help me with this..

jar uf Test.jar com/sendMail/NewClass.class ( Result = no such file or directory )

file name = testMail
replace with = com/sendMail/testMail

This is what I did...

jar uf Test.jar com/sendMail/testMail <<----------------- am I supposed to specify both old and the new file name

If yes, can you provide an example?

Thanks


you need to be in the directory that contains the com directory
You don't actually. You can do

ar uf Test.jar -C DirWithComInIt com/sendMail/testMail
Missing 'j' there of course. The file to be replaced needs to be exactly the same name and path of course
Avatar of g46905

ASKER

Ok.......

I am getting confused here..

I believe we need to specify the new file name ( newFile.class ) and the existing file name ( com/test/newFile.class ) which needs to be replaced in the command line. If we dont do that....how will the executable know which file needs to be what file. Am I missing something...please correct me if I am wrong
Avatar of g46905

ASKER

Oops ...it is 'jar' and it is a typo when I posted you...
You can replace an entry with a different one (different in the sense of a different path in the entry)
>>You can replace an entry

Should have been CAN'T !!
The API documents explain that
Avatar of g46905

ASKER

I hope I am not confusing you..

I am in the /bin directory where I have my Test.jar file and my modified .class file ( For example: testMail.class )

I would like to replace my modified file ( testMail.class ) with com/sendMail/testMail in my Test.jar file.Now, Can you show me the exact command that I need to use?
your class file should be in the correct directory structure
First of all, can you post the result of the following

jar tf Test.jar
Avatar of g46905

ASKER

below is the result...

com/sendMail/BooleanObject.class
com/sendMail/CommentEOLIterator.class
com/sendMail/CompareVersions.class
com/sendMail/testMail.class

Please let me know if you have any questions.
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland 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
Avatar of g46905

ASKER

What is X and Y
Any directory
:-)