For people who are using Eclipse or intelliJ as their IDE might also like to see their changes in serverside Java files applied over the deployed webapp’s immediately.
Lets see how this can be done using Maven
In general, to view the changes immediately, people will edit those files on the exploded directory under webapp. Later, they have to manually copy the changes
to their original workspace. This is a pain for projects which has version control enabled.
Maven comes for resque🙂
Some of the common goals used in Maven based build process includes test, clean, package, install. Apart from this maven provides excellent plugin capability.
One of such plugin allows you to directly deploy your webapp on your java application server like Tomcat/Jetty/Websphere etc.,
Lets see how we can make use of that plugin for inplace or on-the-fly editing and still be on hold with version control system.
The Tomcat Maven plugin provides many goals to play around with webapp’s.
For example, running mvn tomcat:run from the root of the maven based webapp project will deploy the webapp exploded war inside the embedded tomcat.
The deployed webapp can be viewed by browsing http://localhost:8080/
Now their might also be a requirement where you want to make changes on server side Java file and see them being applied immediately on the deployed war file.
Note that, for this to work, you must do editing from Eclipse or IntelliJ kind of IDE’s.
The war:inplace goal from maven helps us to do this easily. Running mvn war:inplace will create the exploded webapp inside src/main/webapp.
Note that this goal does not have any prerequisites, so whenever you use it, you must also do a compile or test preceded if you want to.
Example: mvn clean compile test war:inplace.
Note that the war:inplace goal copies the dependent/external jars into WEB-INF/lib and the compiled classes into
WEB-INF/classes. Do configure your version control system (example subversion) to ignore these files. You can also use clean goal of maven to additionally delete those directories.
If you want to add maven plugin to your project, simply add the below lines to your pom.xml.
For more info on this, please check the Tomcat Maven plugin site.
The Maven2 Jetty plugin provides goals for running a webapplication directly from Maven.
Example: mvn jetty:run will create the exploded war and make it available ruuning on the root context for Jetty server.
mvn war:inplace jetty:run do the simillar job as mentioned in tomcat part above.
To add Jetty plugin, add the following code to your pom.xml
<!– some of the configurations below can also be ignored –>
I have also included a maven based simple web application project (zip file size 22kb).
If you wanna try this stuff mentioned above, please download the application here. This requires you having Maven2 installed as well.