0
votes

Using TomCat 8 in Eclipse Luna...

Before anyone starts freaking out and saying this has been answered before (which it has not because all answers say to use the @WebServlet annotation which doesn't work in this situation) I'd like to point out that I have a specific need/desire to use web.xml to define a servlet.

In order to avoid having to recompile and redeploy an app simply because I changed a value that has the potential to change (for example the IP address of a database), I want to add an init-param tag to the servlet tag in the web.xml file for the application.

But as has been pointed out many times over, adding the servlet tag to web.xml makes it so that tomcat will not start in eclipse - removing the tag and using the @WebServlet annotation fixes the problem.

Unfortunately the error message provided is about as useless as an error message can be when this happens: "Server Tomcat v8.0 Server at localhost failed to start." Also, the console output in eclipse gives this error message "SEVERE: Failed to destroy end point associated with ProtocolHandler ["ajp-nio-8009"] java.lang.NullPointerException" but I can't figure out what this has to do with the web.xml file.

The reason I don't what to use @WebServlet for this particular servlet is because it means I have to recompile and redeploy every time I make a change to the database's IP address - when the better approach would be to make the change in web.xml and simply restart tomcat.

Is there any way to overcome this problem or am I stuck manually deploying the app to tomcat every time I make a change - which is extremely painful during development when changes happen frequently.

2
Create a datasource and use JNDI. - Stefan
Thanks Stefan. But what I'm really after is not a work-around but rather a way to stop tomcat from crashing when adding a servlet definition to web.xml. - stahelim

2 Answers

0
votes

Rather than using web.xml, you could try this:

  1. set Java System Properties using CATALINA_OPTS=-Dmyip=10.0.0.1. Se this link
  2. access the value using System.getProperties()

In Eclipse you edit this in the run configuration for tomcat

0
votes

I just experienced the same challenge and the answer is surprisingly simple and came to it just by chance. When you add new servlet, sort the configurations that define servlet to come first in web.xml then servlet path definitions later. Changing to this order will get tomcat to start and you can proceed to test individual servlets and development.