1

I deployed my WebServices under tomcat 7 without a problem.

Since I tried to install a new instance of WebServices under tomcat 8. It appear to have some problem, the webapp is deployed but when i try: http://locahost:8080/VICWebServices

It just return blank page.

this is the catalina error log I am getting while trying to start the server:

30-Jun-2016 10:56:27.149 SEVERE [localhost-startStop-1]
org.apache.catalina.core.ContainerBase.addChildInternal   ContainerBase.addChild: start: 
org.apache.catalina.LifecycleException: Failed to start component     [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/VICWebServices]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:153)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:587)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1798)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;
at org.apache.tomcat.websocket.server.WsServerContainer.<init>(WsServerContainer.java:150)
at org.apache.tomcat.websocket.server.WsSci.init(WsSci.java:131)
at org.apache.tomcat.websocket.server.WsSci.onStartup(WsSci.java:47)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5292)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)

30-Jun-2016 10:56:27.149 SEVERE [localhost-startStop-1]     org.apache.catalina.startup.HostConfig.deployDescriptor Error deploying configuration descriptor C:\apache-tomcat-8.0.36-AWS-VIC-PROD-2\conf\Catalina\localhost\VICWebServices.xml
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/VICWebServices]]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:729)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:587)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1798)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

30-Jun-2016 10:56:27.150 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDescriptor Deployment of configuration descriptor C:\apache-tomcat-8.0.36-AWS-VIC-PROD-2\conf\Catalina\localhost\VICWebServices.xml has finished in 21,855 ms
30-Jun-2016 10:56:27.152 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-apr-8280"]
30-Jun-2016 10:56:27.162 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-apr-8209"]
30-Jun-2016 10:56:27.166 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 21903 ms

Please advise me on these error messages. Thanks Vic

UPDATE with -verbose:class log

[Loaded javax.servlet.ServletContext from C:\apache-tomcat-8.0.36-AWS-VIC-PROD-2\endorsed\servlet-api.jar]
[Loaded javax.servlet.ServletContextAttributeListener from C:\apache-tomcat-8.0.36-AWS-VIC-PROD-2\endorsed\servlet-api.jar]
[Loaded javax.servlet.ServletContextListener from C:\apache-tomcat-8.0.36-AWS-VIC-PROD-2\endorsed\servlet-api.jar]
[Loaded com.sun.xml.ws.transport.http.servlet.WSServletContextListener from C:\apache-tomcat-8.0.36-AWS-VIC-PROD-2\endorsed\webservices-rt.jar]
[Loaded javax.servlet.ServletContextEvent from C:\apache-tomcat-8.0.36-AWS-VIC-PROD-2\endorsed\servlet-api.jar]
[Loaded javax.servlet.ServletContextAttributeEvent from C:\apache-tomcat-8.0.36-AWS-VIC-PROD-2\endorsed\servlet-api.jar]
Vic
  • 13
  • 1
  • 4
  • Questions seeking debugging help (**"why isn't this code working?"**) must include *the desired behavior*, *a specific problem or error* and *the shortest code necessary* to reproduce it **in the question itself**. Questions without **a clear problem statement** are not useful to other readers. See: [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – Gustavo Morales Jun 30 '16 at 03:38
  • Possibly relevant: http://stackoverflow.com/questions/34950164/getting-nosuchmethoderrorjavax-servlet-servletcontext-getvirtualservername – Tim Biegeleisen Jun 30 '16 at 03:39
  • Its seems server provided servlet-api is updated. `javax.servlet.ServletContext.getVirtualServerName()` exists in ServletContext in api 7 but not in api 6 – Subhrajyoti Majumder Jun 30 '16 at 03:42

3 Answers3

0

The message is

NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;

This means you compiled the code against a version of the servlet library that contains this method, but the server where you deployed the WAR file is running a (probably earlier) version that does not contain this method.

Make sure you are using the same API version in both your build and deployment environments.

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
  • is there any solution to this problem that does not require modification to my existing WebService.war file? – Vic Jul 01 '16 at 00:25
  • Likely you need to deploy a newer version of the servlet container on your server. What application server and what version is on the server, and what version did you compile against? – Jim Garrison Jul 01 '16 at 00:27
  • tomcat 8.0.36 is the web container? sorry i am bit confused with all the terminology. – Vic Jul 01 '16 at 00:36
0

The most probable cause is that you've packaged an older version of the API in the WAR (tomcat should have ignored it) or you you've placed such version in tomcat/lib.

You can identify the offending JAR by running tomcat with verbose class loading. This can be done by adding -verbose:class to the JVM arguments. You can add it there by adding it to the env variable JAVA_OPTS:

  • on linux: export JAVA_OPTS=-verbose:class
  • on windows: set JAVA_OPTS=-verbose:class

Then when you start tomcat, you'll get a lot of output similar to:

[Loaded javax.websocket.server.ServerEndpointConfig$Builder from file:/C:/Users/xxx/Downloads/software/apache-tomcat-8.0.36/apache-tomcat-8.0.36/lib/websocket-api.jar]
[Loaded javax.websocket.server.ServerEndpointConfig from file:/C:/Users/xxx/Downloads/software/apache-tomcat-8.0.36/apache-tomcat-8.0.36/lib/websocket-api.jar]
[Loaded org.apache.tomcat.websocket.server.DefaultServerEndpointConfigurator from file:/C:/Users/xxx/Downloads/software/apache-tomcat-8.0.36/apache-tomcat-8.0.36/lib/tomcat-
[Loaded javax.websocket.server.DefaultServerEndpointConfig from file:/C:/Users/xxx/Downloads/software/apache-tomcat-8.0.36/apache-tomcat-8.0.36/lib/websocket-api.jar]
[Loaded org.apache.tomcat.websocket.pojo.PojoMethodMapping from file:/C:/Users/xxx/Downloads/software/apache-tomcat-8.0.36/apache-tomcat-8.0.36/lib/tomcat-websocket.jar]

Then find from which jar is the servlet context being loaded and remove it if it is not coming from tomcat or fix it version.

Svetlin Zarev
  • 14,713
  • 4
  • 53
  • 82
  • tomcat/lib fold remained the same since Installed it, does that mean it problem is from the actual WAR file, and it has to be re-compiled with new version of API? – Vic Jul 01 '16 at 00:28
  • The issue is because the JVM has loaded an older version of the API. Do what I've said in my answer to find the culprit. – Svetlin Zarev Jul 01 '16 at 05:33
  • I have updated the verbose:class log with all servletcontext related lines, are you saying the problem is caused by those files? – Vic Jul 04 '16 at 00:01
  • Yes, it's the jar that contains them. – Svetlin Zarev Jul 04 '16 at 14:30
0

You have to update the old jars with latest jars which supports tomcat 8 For example some of th restfull api supports only tomcat 7 not not 8 So you have to put lates jars

jersey 1.7 supports tomcat 7 and below

Vinayak Shedgeri
  • 2,222
  • 1
  • 21
  • 24