Posted on 2 mins read

Developing

You can find a few tutorials on how to create a basic (hello world) webapp with java servlets in eclipse so it will not be included here. As always my experience differs from such tutorials. It is never smooth sailing. You always have to configure or troubleshoot something even if your setup is exactly the same. The last time I did something with Servlets or JSP was in 2013 or 2014. I don’t think I have my notes from then.

This time round I had to do some tweaking to get Eclipse to recognise the tomcat server installed on OSX (not the VM, thats working well). For some reason it didn’t recognize tomcat 8.5.*.

You have to patch catalina.jar, as this is version number the WTP adapter looks at. It's a quite useless check, and the adapter should allow you to start the server anyway, but nobody has though of that yet.

For years and with every version of Tomcat this is always a problem.

To patch you can do the following:

cd [tomcat or tomee home]/lib
mkdir catalina
cd catalina/
unzip ../catalina.jar
vim org/apache/catalina/util/ServerInfo.properties
Make sure it looks like the following (the version numbers all need to start with 8.0):

server.info=Apache Tomcat/8.0.0
server.number=8.0.0
server.built=May 11 2016 21:49:07 UTC
Then:

jar uf ../catalina.jar org/apache/catalina/util/ServerInfo.properties
cd ..
rm -rf catalina

stack link

Once this was done, I could develop and test my webapp in Eclipse.

Deploying

To me, running the webapp in the IDE is not deploying. There were a few tutorials with misleading titles.

I was told that to deploy an webapp is bascially copying a war archive into a directory for tomcat. To have a 2nd opinion, I found this vogella tutorial. Vogella has been consistent in providing great tutorials to help you get started.

In Eclipse, you just right click on the root package for your webapp and export as a war archive and save it somewhere.

To transfer the file to the VM:

scp <filename>.war tomcatuser@192.168.56.101:/home/<vm user>

And via ssh in /opt/tomcat (assuming you set up tomcat here and service is called tomcat8):

cp ~/<filename>.war webapps/
sudo service tomcat8 restart

Now going to <url>:8080/<filename>/<classname> should load your webpage or whatever response you made. You could change the URL by specifying configurations in a web.xml but that will not be covered here… for now?