Java EE 6 Servlet – TomEE – Caused by: java.lang.IllegalArgumentException: Invalid in servlet mapping

Posted on Updated on

How bad a plain vanilla servlet can go with annotations??? Let’s see what happens if we miss a simple “/”.

So I configured a simple Servlet in eclipse, see the code below

package com.mumz.test.javaee.servlet;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

 * Servlet implementation class MySecondServlet.
public class MySecondServlet extends HttpServlet {
	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 1L;
     * The Constructor.
     * @see HttpServlet#HttpServlet()
    public MySecondServlet() {

	 * Do post.
	 * @param request the request
	 * @param response the response
	 * @throws ServletException the servlet exception
	 * @throws IOException the IO exception
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.getWriter().println("Welcome to second servlet");

I am using Apache TomEE, so I wrote this servlet and started my TomEE.

My console was filled up with below stacktrace:

SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/MyServlet]]
	at java.util.concurrent.FutureTask.get(
	at org.apache.catalina.core.ContainerBase.startInternal(
	at org.apache.catalina.core.StandardHost.startInternal(
	at org.apache.catalina.util.LifecycleBase.start(
	at org.apache.catalina.core.ContainerBase$
	at org.apache.catalina.core.ContainerBase$
	at java.util.concurrent.ThreadPoolExecutor.runWorker(
	at java.util.concurrent.ThreadPoolExecutor$
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/MyServlet]]
	at org.apache.catalina.util.LifecycleBase.start(
	... 6 more
Caused by: java.lang.IllegalArgumentException: Invalid <url-pattern> secondServlet in servlet mapping
	at org.apache.catalina.core.StandardContext.addServletMapping(
	at org.apache.catalina.core.StandardContext.addServletMapping(
	at org.apache.catalina.deploy.WebXml.configureContext(
	at org.apache.catalina.startup.ContextConfig.webConfig(
	at org.apache.tomee.catalina.OpenEJBContextConfig.webConfig(
	at org.apache.catalina.startup.ContextConfig.configureStart(
	at org.apache.tomee.catalina.OpenEJBContextConfig.configureStart(
	at org.apache.catalina.startup.ContextConfig.lifecycleEvent(
	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(
	at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(
	at org.apache.catalina.core.StandardContext.startInternal(
	at org.apache.catalina.util.LifecycleBase.start(
	... 6 more

And what is the reason???

In my URL pattern I had forgotten a slash “/”

public class MySecondServlet extends HttpServlet

And the correction is:

public class MySecondServlet extends HttpServlet {

Tomcat Cannot assign requested address: JVM_Bind

Posted on

Today I started getting this weird looking exception while launching tomcat.

SEVERE: StandardServer.await: create[localhost:8005]: Cannot assign requested address: JVM_Bind
        at Method)
        at org.apache.catalina.core.StandardServer.await(
        at org.apache.catalina.startup.Catalina.await(
        at org.apache.catalina.startup.Catalina.start(
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(
        at java.lang.reflect.Method.invoke(
        at org.apache.catalina.startup.Bootstrap.start(
        at org.apache.catalina.startup.Bootstrap.main(

I googled around and most answers were pointing towards Port is already being used, which definitely wasn’t the issue in my case, anyways after spending few hours I figured out my main issue was that my IPV4 address changed. Although I never updated my server.xml to change localhost to any specific IP address but yet I started getting this error.

The actual cause of this issue was my host file present at WINDOWS_INSTALLTION/windows/System32/drivers/etc, where in which my old IP address was mapped against localhost like below: localhost
192.168.XXX.XX localhost

This second line was the main culprit, there are two ways of solving this:

  1. Remove 192.168.XXX.XX localhost line completely from host file
  2. Replace old IP with new IP in your host file i.e instead of 192.168.XXX.XX localhost change it to 192.168.XXX.YY localhost

Hope this helps!