[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

command to replace a .class file in my jar?

Posted on 2006-03-27
21
Medium Priority
?
248 Views
Last Modified: 2010-03-31
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.

0
Comment
Question by:g46905
  • 11
  • 7
  • 3
21 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 16303630
You can't - you need to create a new jar
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16303647
Oh wait

jar uf yourjar.jar NewClass.class

would replace the one of the same name
0
 

Author Comment

by:g46905
ID: 16303919
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.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 92

Expert Comment

by:objects
ID: 16303988
Yes you would need to specify the full path

jar uf yourjar.jar com/sendMail/NewClass.class
0
 

Author Comment

by:g46905
ID: 16304419
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


0
 
LVL 92

Expert Comment

by:objects
ID: 16304477
you need to be in the directory that contains the com directory
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16304524
You don't actually. You can do

ar uf Test.jar -C DirWithComInIt com/sendMail/testMail
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16304564
Missing 'j' there of course. The file to be replaced needs to be exactly the same name and path of course
0
 

Author Comment

by:g46905
ID: 16304615
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
0
 

Author Comment

by:g46905
ID: 16304643
Oops ...it is 'jar' and it is a typo when I posted you...
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16304763
You can replace an entry with a different one (different in the sense of a different path in the entry)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16304778
>>You can replace an entry

Should have been CAN'T !!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16304943
The API documents explain that
0
 

Author Comment

by:g46905
ID: 16305015
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?
0
 
LVL 92

Expert Comment

by:objects
ID: 16305076
your class file should be in the correct directory structure
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16305092
First of all, can you post the result of the following

jar tf Test.jar
0
 

Author Comment

by:g46905
ID: 16305191
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.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 400 total points
ID: 16305214
>>com/sendMail/testMail.class

Can only be replaced by

X/com/sendMail/testMail.class
Y/com/sendMail/testMail.class

etc.

Is that the case?
0
 

Author Comment

by:g46905
ID: 16305236
What is X and Y
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16305325
Any directory
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16580095
:-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month19 days, 7 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question