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.

g46905Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

jar uf yourjar.jar NewClass.class

would replace the one of the same name
0
g46905Author 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.
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

objectsCommented:
Yes you would need to specify the full path

jar uf yourjar.jar com/sendMail/NewClass.class
0
g46905Author 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


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

ar uf Test.jar -C DirWithComInIt com/sendMail/testMail
0
CEHJCommented:
Missing 'j' there of course. The file to be replaced needs to be exactly the same name and path of course
0
g46905Author 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
0
g46905Author Commented:
Oops ...it is 'jar' and it is a typo when I posted you...
0
CEHJCommented:
You can replace an entry with a different one (different in the sense of a different path in the entry)
0
CEHJCommented:
>>You can replace an entry

Should have been CAN'T !!
0
CEHJCommented:
The API documents explain that
0
g46905Author 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?
0
objectsCommented:
your class file should be in the correct directory structure
0
CEHJCommented:
First of all, can you post the result of the following

jar tf Test.jar
0
g46905Author 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.
0
CEHJCommented:
>>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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
g46905Author Commented:
What is X and Y
0
CEHJCommented:
Any directory
0
CEHJCommented:
:-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.