Although there are now a variety of intelligent IDE can generate for us jar package, war package, ear package, even with automatic replacement, deployment features. But there will be times when you need to modify or replace a jar package, a war package, a file in the ear package instead of a whole rebuild. For example, you have an ear pack that has been deployed to a client's server, it's been running for so long and the version is very old, but a bug that bugs you needs to fix it immediately at the customer, the ear bag is big, and the customer's network is slow and you don't have the old code. But you know you just need to change a class file to fix it. If you follow the normal process, that is generally you have to submit code, by CI compiled an RPM package, in the client's server redeployment, and then verify that the day Lily is cool, the customer has scolded you countless times of incompetence.
That's when we're going to have to make hot replacements (I've written an article about hot deployment, but that's through the JDK's own features, here's a hard replacement file), and thankfully, all Java application servers now support hot deployment. So we just need to get into the path to the application server, and we can change the bug's class file or jar file, whatever else, and replace it with the ear bag. The application server then checks to see that the ear package has been updated and is automatically hot-deployed.
The tools used here are two, jars and 7z, why jars are compared to 7z or zip, because jar packages, war packages, ear packs, are essentially zip packages or compressed package jar Command
This is the JDK's own tool. Targeted, only know the following four commands plus the VF suffix:
Command |
explain |
C |
Create a new compressed package |
T |
List all contents in a compressed package |
X |
Extract the specified file or entire compressed package into the current directory |
U |
Update the current compression pack |
V |
Print all the actions you trigger to the standard output |
F |
You can specify the name of the compressed package |
Note: The compression pack here can be jar, war, ear, or what ever else, and you just specify the suffix name you want when you call the jar.
Then, in the next example, you are creating a compressed package with JAR-CVF or JAR-XVF or JAR-UVF:
This is not our focus, but for you to express the essence of JAR-CVF is compressed package, and what is the suffix name line. Suppose you have the following file:
Call JAR-CVF bb.cc *, compress all files under the folder into file bb.cc, or you can be Bb.jar, Bb.war, bb.ear
Open with 7z or zip:
Shows that this is a simple compression package, just one more Meta-info folder. No he replaces the file in the jar, War, ear package:
This is our focus, the main use is a combination of commands, JAR-TVF + JAR-XVF + JAR-UVF.
Use your imagination, this example.ear is deployed on the server, the process of compiling and deploying is complex, you do not want to recompile and deploy this exmple.ear just want to replace the file inside.
First use JAR-TVF to see what's in the file, suppose we want to replace the inside Ejbcomponent.jar
This jar is very small, 50k, we modify this file and put it in the same directory:
To perform the JAR-UVF example.ear Ejbcomponent.jar, we can see that the new Ejbcomponent.jar has been replaced in the ear packet
Then play the imagination again, this ear is in the application server's deployment directory, hot deploy is open, the server will find this ear package creation time updated, will redeploy this ear package
Note: In the example above, the directory structure of the ear package is very simple, all the files are basically in the root directory, if you want to replace the files in the subdirectory, you need to first execute the JAR-XVF command, you need to replace the file first extract (together with the directory structure to extract to the current directory), The new file is then replaced with the file in the unpacked directory structure, and then the JAR-UVF is executed. (If you don't understand, comment inside) modify the files in the jar, War, ear package:
If it is modified, it proves that basically you want to modify the impossible is the class file or jar file, what must be xml,properties, such as packaging in the package of files, at this time with 7z horse, directly open compression, edit, you can:
Save after editing,
To delete a file in the jar, war, and ear package:
Simple, 7z open, delete directly