0

After many years away from java (I was lost in .net land, if that is usefull) I now find myself in a "java 7" shop (I'm told this will not change) and I'm trying to follow the tutorial at http://www.mkyong.com/webservices/jax-rs/jersey-hello-world-example/ and no matter what I do, tomcat7 is reporting a very fast 404 error no matter what I do.

I have googled for this for the past few days - its been a low priority until now - and I have not found anything that can help me. None of my peers can figure this out. I have no firewalls in the way and I am using the same version everybody else on my team is. I have tried multiple things and every search result I have found has simply not worked.

I'm not sure what to do; I'm currently being forced to use the Kepler version of Eclipse and while so I need to get this working in eclipse, with tomcat7, and I am making absolutely no progress due to this issue.

  • Eclipse: Kepler but "enterprise-ized" that I cant control. aka we must use it.
  • Tomcat: Tomcat7

Project was generated in maven as a "webapp" archetype and then imported into eclipse, the only thing I did not do to the letter by that tutorial was run "eclipse:eclipse in maven as the first time I did that it corrupted the project and created a var-type in the classpath that maven/eclipse doesn't understand (type: 4) so i redid everything from scratch without running that command and then imported it into eclipse successfully.

Question: What am I doing wrong? How do I debug this and help myself?

I'm under the impression that tomcat normally has a manager/UI that can be used to help debug, but even after looking at the docs for tomcat and then copy and pasting the configuration they say to use to enable it, then bouncing the tomcat service and reloading eclipse, I still get that 404 error no matter what url/link I go to.

Thank you in advance.

The only logs I get are as follows:

May 06, 2015 2:32:40 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Users\duking\Desktop\ride-5.1.1-win64\OpenJDK\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\RSA SecurID Token Common;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Microsoft Application Virtualization Client;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Common Files\Hitachi ID\;C:\Program Files (x86)\Git\cmd;C:\Program Files\TortoiseGit\bin;C:\bin;C:\Program Files\Java\jdk1.7.0_79\bin;C:\Program Files (x86)\WinMerge;c:\cygwin64\bin;c:\cygwin64\usr\bin;C:\Program Files (x86)\Nmap;.
May 06, 2015 2:32:41 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
May 06, 2015 2:32:41 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
May 06, 2015 2:32:41 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8081"]
May 06, 2015 2:32:41 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
May 06, 2015 2:32:41 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8082"]
May 06, 2015 2:32:41 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
May 06, 2015 2:32:41 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8083"]
May 06, 2015 2:32:41 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
May 06, 2015 2:32:41 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 624 ms
May 06, 2015 2:32:41 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
May 06, 2015 2:32:41 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.47
May 06, 2015 2:32:41 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
May 06, 2015 2:32:41 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8081"]
May 06, 2015 2:32:41 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8082"]
May 06, 2015 2:32:41 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8083"]
May 06, 2015 2:32:41 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
May 06, 2015 2:32:41 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 582 ms
honestduane
  • 579
  • 6
  • 13
  • Give us the log or stack trace . Do you have web.xml ? if so paste that too. – Shahzeb May 06 '15 at 21:59
  • If you download and run the zip file that is availble in his tutorial does that work ? – Shahzeb May 06 '15 at 22:01
  • I just get the same 404 page no matter what I do even if I use the downlaod from that link – honestduane May 06 '15 at 22:12
  • I think it has not been deployed. You right clicked Tomcat and in eclipse servers tab and gone to add applications and added this application? – Shahzeb May 06 '15 at 22:17
  • Yes, added for deployment and restarted/synced and still nothing. – honestduane May 06 '15 at 23:31
  • There should be more logs then. It is either not added or posted log is not complete. In the logs there should be mention of application and its startup etc – Shahzeb May 06 '15 at 23:33
  • Can you show (1) some relevant code (2) Your app configuration (3) Your project dependencies – Paul Samsotha May 07 '15 at 00:27
  • @peeskillet I'm using the download at that link. It contains everything. – honestduane May 07 '15 at 00:28
  • @Shahzeb I can''t find any other logs. I used process explorer to look for open file handles just to make sure and I cant find anything. Where would they be? – honestduane May 07 '15 at 00:29
  • But anyway, if you are just starting out, you should just use the Jersey archetype. [See here](http://stackoverflow.com/a/30020830/2587435). You should be able to run it as is `http://localhost:port/project-name/webapi/myresource`. If it doesn't work, then the problem might be somewhere else. This project should work out the box – Paul Samsotha May 07 '15 at 00:30

1 Answers1

0

I'm not sure what it was but I managed to get a simple get working using these in the pom:

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-server</artifactId>
    <version>1.17.1</version>
</dependency>
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-core</artifactId>
    <version>1.17.1</version>
</dependency>
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-servlet</artifactId>
    <version>1.17.1</version>
</dependency>

And updating my web.xml to use v1 xml configuration:

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">
    <display-name>REST Web Application Demo</display-name>
    <servlet>
        <servlet-name>jersey-serlvet</servlet-name>

        <!-- v1 -->
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>

        <load-on-startup>1</load-on-startup>
        <init-param>

            <!-- v1 Packages Reference -->
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>com.example.app</param-value>

        </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>jersey-serlvet</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
</web-app>

But now sadly I'm now getting a very different exception:

javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax/ws/rs/MessageProcessingException
    com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:420)
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
root cause

java.lang.NoClassDefFoundError: javax/ws/rs/MessageProcessingException
    org.apache.cxf.jaxrs.impl.ResponseBuilderImpl.build(ResponseBuilderImpl.java:69)
    com.example.app.ApiService.responseMsg(ApiService.java:27)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:606)
    com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
    com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)
    com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
    com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
    com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
    com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
    com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
    com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
    com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
    com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
    com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
honestduane
  • 579
  • 6
  • 13