Java web application development have been criticized a lot in the past as painful compared to building building php web application. When developing an application in php, developers would refresh the browser to see changes they have made.
In java, the developer would have to restart the server and then refresh the browser. This process limits developer productivity. JRebel was created to solve this problem and has done this very well. The only problem is that jrebel is not free.
A free alternate to jrebel is "Dynamic Code Evaluation Virtaul Machine" or "DCEVM" . I wrote about DCEVM a while back. This article would describe how I use it in my development environment. My environment consist of the following tools
- Eclipse
- TomEE
- JDK 7 update 51 and above with DCEVM installed
Let's get started. If you haven't downloaded these tools , do so now.
Install DCEVM
To install DCEVM, download the jar file to your machine and execute the jar
Select the JDK you want to install DCEVM into and click on "Install DCEVM as altjvm"
Setting up the project in eclipse
Next step would be to create a "Dynamic Web project" or a "Java project" in eclipse. There are many articles/tutorials on the internet describing the process of creating a java project in eclipse.
I am not going to cover that in this article. I normally create my projects manually and then configure them in eclipse.
Here is an example of my folder structure and configuration.
My project's folder structure from package explorer under Java perspective.
Let's prepare TomEE for development purposes.
Go to TomEE's web.xml file in tomee/conf/web.xml "org.apache.jasper.servlet.JspServlet".
Change the development init param value to true.
Next add a user library to eclipse that contains all the libraries that comes with TomEE.
Right click on your project > select properties> Java build path > The library tab Click on Add Library > User Library > Next > Select EXTENDIT_TOMEE > Finish > Ok
Note : You can also just add the jar files(tome's libraries) to the project's build path.
Under TomEE's conf folder, create an xml file (context file) called ROOT.xml( or the name of your context) .
The content of your file should look like this below:
Next create a servlet and a service bean extendit.TestServlet.java
extendit.TestService
Next , create a "Run Configuration" for the application in eclipse.
In the main class section and the Boostrap class from TomEE : org.apache.catalina.startup.Bootstrap On the "Arguments" tab :
- add "start" to "Program arguments"
- add the following to the "VM arguments" ( configure to you own environment)
-Dfile.encoding=UTF -Djava.endorsed.dirs="tomee/endorsed" -Dcatalina.base="tomee" -Dcatalina.home="tomee" -Djava.io.tmpdir="tomee/temp" -XXaltjvm=dcevm
On the "Classpath" tab:
- add eclipse bootstrap jars from TomEE's bin folder
On the "Common" tab
- Select "Debug" and "Run"
Click Apply and Close "Run Configuration".
Configure project's deployment descriptor
Add bean.xml and web.xml to WEB-INF folder under webapp directory.
beans.xml
web.xml
Next Run, your project with the debug configuration. Make changes to the service class and refresh your browser.