0

I am setting up my Jersey Web Service but cant get it to run, Apache Tomcat 8.5 is error'ing out. See details below for simple code, my libs and error.

I created a Dynamic Web Project... I added my Jersey files... (am i missing any?)

  • javax.ws.rs-api.2.0.1.jar
  • jersey-client.jar
  • jersey-common.jar
  • jersey-contaner-servlet.jar
  • jersey-container-servlet.jar
  • jersey-media-jaxb.jar
  • jersey-server.jar

My Web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
 <servlet>
    <servlet-name>myApi</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <!-- The package where your resource classes are -->
        <param-value>WS</param-value>
    </init-param>
</servlet>
<servlet-mapping>
    <servlet-name>testApi</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>

My Java class

package ws;
import javax.ws.rs.*;
import javax.ws.rs.core.*;

    @Path("test")
    public class Connect {
        @GET
        @Path("test")
        @Produces(MediaType.TEXT_PLAIN)
        public String hello(){
            return "hello world";
        }
    }

My error before the pop-up saying failed to start Apachev8.5

SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/ThisApi]]
    at java.util.concurrent.FutureTask.report(Unknown Source)
    at java.util.concurrent.FutureTask.get(Unknown Source)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:911)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:890)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1403)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1393)
    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: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/ThisApi]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
    ... 6 more
Caused by: java.lang.NoClassDefFoundError: jersey/repackaged/com/google/common/base/Function
    at org.glassfish.jersey.internal.ServiceFinder.<clinit>(ServiceFinder.java:165)
    at org.glassfish.jersey.servlet.internal.ServletContainerProviderFactory.getAllServletContainerProviders(ServletContainerProviderFactory.java:66)
    at org.glassfish.jersey.servlet.init.JerseyServletContainerInitializer.onStartup(JerseyServletContainerInitializer.java:134)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5178)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 6 more
Caused by: java.lang.ClassNotFoundException: jersey.repackaged.com.google.common.base.Function
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1285)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
    ... 11 more
Fearghal
  • 10,569
  • 17
  • 55
  • 97
  • 1
    See if this helps...this is for tomcat 7. Answer has listed all dependencies, http://stackoverflow.com/questions/22754372/jersey-2-7-issue-while-running-it-on-apache-tomcat-7-0 – Santo Feb 08 '17 at 19:27
  • I think so....ridiculous how may libs i needed, not sure which caused the difference but i'll hae to check that out another time....any idea what my test url is going to be? – Fearghal Feb 08 '17 at 19:35
  • localhost:port/your apps contextroot/test – Santo Feb 08 '17 at 19:39
  • hmmmm no doesnt seem to work.. I have /test/test from the java code...i have localhost:8081/ (thats ok) and my localroot - how do i determine if this is right? I also see paramValue in xml...so that gives me localhost:8081\contextroot\WS\test\test – Fearghal Feb 08 '17 at 19:45
  • Should be: localhost:8081/test/test – FrAn Feb 08 '17 at 20:21
  • hmmm im getting 404 errors even at localhost... tomcat config issue perhaps – Fearghal Feb 08 '17 at 22:19

1 Answers1

1

You are missing jersey-guava.jar, which should contain the package-rebundled versions of the Google Guava classes, including Function. Jersey repackages the exact version they need so that you can still use the version of Guava you prefer from its original package structure. See https://stackoverflow.com/a/22069399/27905 .

https://mvnrepository.com/artifact/org.glassfish.jersey.bundles.repackaged/jersey-guava

Community
  • 1
  • 1
nitind
  • 19,089
  • 4
  • 34
  • 43
  • Hey man, i added it as part of a fix to get tomcat running but...now i get http status 404 error – Fearghal Feb 10 '17 at 13:34
  • still having this error. tomcat manually started i can hit the localhost....i start my web service i cant hit local host – Fearghal Feb 13 '17 at 18:49
  • @Fearghal You should open a new question for that, including details of how you're deploying and launching Tomcat and your web app within it. – nitind Feb 13 '17 at 18:57
  • I did including my libs, my code, my tomcat version, some troubleshooting i did....http://stackoverflow.com/questions/42211334/tomcat-gives-http404-error-when-used-to-test-jersey-java-web-service – Fearghal Feb 13 '17 at 19:06