I am using a runnable jar (with-depenencies) to start an embedded tomcat that hosts a webapplication which uses struts2 and websockets.

The application works propperly when running in an Tomcat installation, but when run from the mentioned runnable jar, the websocket container is not initialized, resulting in 404 responses when trying to connect to the corresponding end point.

I narrowed the problem to the discovery processes which reads the META-INF/Services/javax.servlet.ServerContainerInitializer of the different jar files to find the classes that initialize services for the server. In particular, the class that initializes the Websockets Container is org.apache.tomcat.websocket.server.WsSci.

As far as I can see the WsSci class has been repackaged in the runnable jar by the maven assembly plugin, but the META-INF/Services/javax.servlet.ServerContainerInitializer file doesn't mention this class in the way the original jar did, it only mentions the org.apache.jasper.servlet.JasperInitializer initializer.

Is there any way I could leave the runnable jar as it is and programatically request the WebSockets Container initializacion by calling some method on the Tomcat class? Or request the initialization in a web.xml file?

Note: as a work arround I could see that if I add the WsSci class manually to the new META-INF/Services/javax.servlet.ServerContainerInitializer file in the runnable jar, the Websockets Containter initializes correctly.

1

There are 1 answers

0
Razak Dangi On

I encountered similar problem, problem could be claassloader,

Tomcat loads ServerContainerInitializer from parent classloader

    String configFile = "META-INF/services/" + serviceType.getName();
    ClassLoader loader = this.context.getParentClassLoader();

Probably in your tomcat initialization code , you could set to use your classloader instead of webApp classloader.

tomcatContext.setParentClassLoader(this.getClass().getClassLoader());