问题
I have read many posts about changing the contents of a file and replace the whole file, but little did I understand.
Referred this too. The .sh is the one that confuses me. Do I need to use .sh in my case too. I don't want to ruin the project by trying something new, without much understanding.
How do I replace a class file in a jar? I have the class file ready from my workspace. All I need to do is replace the already present class file in the jar. Moreover, need I restart the server after replacing, to see effects?
The application server that we are using is IBM websphere.
Should I also navigate to my ear file location in the server? For example, cd aaa/bbb/ccc and then execute the command.
Please help, I am totally new to this.
回答1:
To extract/pull a particular class from your ear:
jar -xf sample.ear com/sample/Example.class
then overwrite com/sample/Example.class
with your generated class and finally do:
jar -uf sample.ear com/sample/Example.class
To update the ear file again with updated class file.
PS: This will require you to deploy the ear file again on your app server and then restart the app server. I would also suggest looking into ant
or maven
for this task.
回答2:
.sh file is an example of one of the file from jar that you wish to extract it from jar and edit the extracted file and then again archive it back to the jar... in EXAMPLE
so you don't need .sh if your file name is not ending with .sh..
来源:https://stackoverflow.com/questions/22627541/shell-script-to-replace-a-class-file