We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

command to replace a .class file in my jar?

g46905
g46905 asked
on
Medium Priority
365 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.

Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016

Commented:
You can't - you need to create a new jar
CERTIFIED EXPERT
Top Expert 2016

Commented:
Oh wait

jar uf yourjar.jar NewClass.class

would replace the one of the same name

Author

Commented:
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.
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
Yes you would need to specify the full path

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

Author

Commented:
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


Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
you need to be in the directory that contains the com directory
CERTIFIED EXPERT
Top Expert 2016

Commented:
You don't actually. You can do

ar uf Test.jar -C DirWithComInIt com/sendMail/testMail
CERTIFIED EXPERT
Top Expert 2016

Commented:
Missing 'j' there of course. The file to be replaced needs to be exactly the same name and path of course

Author

Commented:
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

Author

Commented:
Oops ...it is 'jar' and it is a typo when I posted you...
CERTIFIED EXPERT
Top Expert 2016

Commented:
You can replace an entry with a different one (different in the sense of a different path in the entry)
CERTIFIED EXPERT
Top Expert 2016

Commented:
>>You can replace an entry

Should have been CAN'T !!
CERTIFIED EXPERT
Top Expert 2016

Commented:
The API documents explain that

Author

Commented:
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?
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
your class file should be in the correct directory structure
CERTIFIED EXPERT
Top Expert 2016

Commented:
First of all, can you post the result of the following

jar tf Test.jar

Author

Commented:
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.
CERTIFIED EXPERT
Top Expert 2016
Commented:
>>com/sendMail/testMail.class

Can only be replaced by

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

etc.

Is that the case?

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
What is X and Y
CERTIFIED EXPERT
Top Expert 2016

Commented:
Any directory
CERTIFIED EXPERT
Top Expert 2016

Commented:
:-)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.