Is it possible to update a Java web application by replacing only files of the same class?

Sometimes, when we make small changes in our web applications, for example, fixing bugs, we do not create a whole new WAR file each time, but simply replace only the affected class files in the exploded web application directory under WEB-INF/classes and restart the application .

This is normal?

+6
java web-applications
source share
6 answers

I would say that this is probably not the best practice because of the version: how do I know which version of the application you have deployed? If you deploy the .war file, the build process can take care of updating the build number (from the original control or separately, no matter how each has a different number, that's OK).

If you use continuous integration (and this is definitely a good idea), then your build process should pop up an “artifact” (war file) every time you make changes to the source code. also possibly tagging version control with build number.

So, when you deploy your web application, you know exactly which version works and what source code makes up this version.

Making small incremental changes by updating individual .class files, I would say, is probably not a good idea for anything other than testing a local developer.

+13
source share

You can solve your deployment tasks with maven.

Every time you change something, just type

 svn update mvn clean compile war:exploded tomcat:inplace -P deployment 

you have a deployment profile in your pom.xml file containing all the configuration needed for the deployment environment.

this way you can organize the automation of the deployment process and never crash when copying the wrong / old / etc files manually.

+2
source share

@Phill Sacre and others looked at most aspects of this issue. I came across a different aspect and would like to contribute.

Short answer: No, this may not be enough to replace only class files for modified java files. Read more.

Here is my script.

  • I had a .java containing mostly SQL queries. I changed one request, placed a new .class file and bounced Tomcat (not connected to my IDE). The previous request was still in progress.
  • When I replaced all .class files, a new request was executed.

To diagnose

  • I took two maven assemblies and performed a directory comparison.
  • To my surprise, I found that 2.class files, not 1 , were changed.
    • This additional .class file actually used the .class file that I modified.
  • When I looked at the decompiled version of the additional .class file, I realized that the SQL query (String) exists as inline .

This clearly explains why replacing one class did not solve the problem. Replacing the first .class file will never be effective in this case.

Lessons learned. Here is how I generalized my teaching:

  • During development, the IDE (I use Eclipse) takes care of the hot deployment.
  • On production systems, it would not be wise to assume that replacing just one .class file would be enough. Full deployment needs to be considered.
+2
source share

Agree with PHill; it seems that the time savings are negligible, and the potential risks are many.

0
source share

Technically speaking, as long as the class / method signatures are the same, it should work. But, as Phill points out, this is not the best idea in the world.

I assume that you are not using Apache Ant and Apache Maven to create your .war file. I highly recommend that you choose a tool that can automate the creation of the .war file to avoid the manual hacks you are talking about. I personally use Maven and it takes care of compiling, performing unit tests and packaging my application. Good stuff:)

0
source share

The introduction of an updated class file into the application should be performed only on a limited basis and should not be a standard action for assembly. At the same time, I saw how this was done in large applications, where the whole rebuild / repacking took several hours, and error correction was necessary as soon as possible. Hope this helps.

0
source share

All Articles