When it comes to simple web application development with Eclipse, I have been a keen user of Sysdeo’s Tomcat Eclipse Plugin. However, I must admit, that there are some things that could be easier. The installation procedure can be a little too complicated for webapp-beginners .
So, I have been looking for a simpler setup that I could use in developing and running my web applications. That is how I came across Winstone – a lightweight servlet container. Ok, this wasn’t the first server being “lightweight” and “simple to use” and that could be “easy to embed”, but these were the features I had been searching for so I decided to give it a try.
Running servlets
It looked very promising when I first started the IT Mill Toolkit demo war and it ran out-of-the-box:
Also, it worked nicely with the extracted war-archives.
Running the Eclipse project using Ant
We have been using the following structure for a Java web application:
WEB-INF/
src/
classes/
lib/
itmill-toolkit-4.0.1.jar
tmill-toolkit-src-4.0.1.jar
itmill-toolkit-themes-4.0.1.jar
web.xml
itmill-toolkit-license.xml
<static html pages go here>
Mainly standard servlet stuff, with the exception that the src folder is also within the WEB-INF folder. This is something inherited from the Tomcat plugin, but it has proven to be very convenient.
As this is exactly what a servlet container expects, it is very seamless to run it. I added the winstone.jar file into the project together with a simple Ant build script:
server
winstone-0.9.8.jar
build.xml
In build.xml I created a target that ran Winstone and used the project as a web root folder:
This seemed to work pretty well, but there were still some problems:
Stopping the server was complicated. The server remained in the background and would not stop without contacting the Task Manager.
I was not able to debug my Java application as I’ve grown used to with Tomcat.
And as the debug did not work, nor did the hot code replace feature of JVM.
Something had to be done.
Running an embedded Java servlet container
So, I decided to create a small wrapper application around the Winstone and start it directly. This should enable the debugging and hot code replace feature of JVM.
And it worked just as I hoped it would! I was able to start the project and debug it using Eclipse JDT. Only some finishing touches like automatic webroot detection, cleaner packaging and automatically launching browser to correct address were missing.
Tadaa!
The final project structure looks like this:
WEB-INF/
src/
<Application source code go here>
classes/
<Eclipse automatically compiles here>
lib/
itmill-toolkit-4.0.1.jar
itmill-toolkit-src-4.0.1.jar
itmill-toolkit-themes-4.0.1.jar
web.xml
itmill-toolkit-license.xml
server
src/
com.itmill.toolkit.ServerLauncher.java
com.itmill.toolkit.BrowserControl.java
winstone-0.9.8.jar
Both the server/src folder and the winstone.jar have to be in the project build path so you can run the project as normal Java application.