Reputation: 222722
I am very new to Java, and i have followed a tutorial to create an JAX-RS service, everything i did was according to the tutorial, but cannot get it to work. I have attached the screen shot and logs.
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">
<display-name>com.duo.test</display-name>
<servlet>
<servlet-name>Jersey Rest Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.duo.test</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Rest Service</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
</web-app>
MY class:
package com.duo.test.status;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
@Path("/v1/status/*")
public class V1_status {
@GET
@Produces(MediaType.TEXT_HTML)
public String returnTitle()
{
return "<p> Java Web Serbice</p>";
}
}
Logs:
Sep 23, 2014 12:22:56 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:\Program Files\Java\jre7\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;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:\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 (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Microsoft\Web Platform Installer\;D:\ndk;C:\ant\;C:\Program Files\Java\jdk1.7.0_07\bin;D:\Softwares\Ecclipse\Ecclipse\sdk\build-tools\18.1.0;C:\Program Files (x86)\Windows Kits\8.0\Windows Performance Toolkit\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\Takipi\lib;C:\Takipi\lib32;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;C:\Program Files (x86)\nodejs\;JAVA_HOME%\bin;C:\apache-ant-1.9.4\bin;C:\adt-bundle\sdk\platform-tools;C:\adt-bundle\sdk\tools;;C:\Program Files (x86)\Java\jdk1.6.0_39\bin;C:\Users\sajeetharan.DUOSL.000\AppData\Local\Android\android-sdk\tools;C:\Users\sajeetharan.DUOSL.000\AppData\Local\Android\android-sdk\platform-tools;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;;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:\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 (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Microsoft\Web Platform Installer\;D:\ndk;C:\ant\;C:\Program Files\Java\jdk1.7.0_07\bin;D:\Softwares\Ecclipse\Ecclipse\sdk\build-tools\18.1.0;C:\Program Files (x86)\Windows Kits\8.0\Windows Performance Toolkit\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\Takipi\lib;C:\Takipi\lib32;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;C:\Program Files (x86)\nodejs\;JAVA_HOME%\bin;C:\apache-ant-1.9.4\bin;C:\adt-bundle\sdk\platform-tools;C:\adt-bundle\sdk\tools;;C:\Program Files (x86)\Java\jdk1.6.0_39\bin;C:\Users\sajeetharan.DUOSL.000\AppData\Local\Android\android-sdk\tools;C:\Users\sajeetharan.DUOSL.000\AppData\Local\Android\android-sdk\platform-tools;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\\tools;C:\apache-ant-1.9.4\bin;C:\adt-bundle\sdk\tools;C:\adt-bundle\sdk\platform-tools;c:\users\sajeetharan.DUOSL.000\AppData\Roaming\npm\;.
Sep 23, 2014 12:22:57 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:com.duo.test' did not find a matching property.
Sep 23, 2014 12:22:57 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Sep 23, 2014 12:22:57 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Sep 23, 2014 12:22:57 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
Sep 23, 2014 12:22:57 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Sep 23, 2014 12:22:57 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 2349 ms
Sep 23, 2014 12:22:58 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Sep 23, 2014 12:22:58 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.12
Sep 23, 2014 12:23:01 PM com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
com.duo.test
Sep 23, 2014 12:23:01 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
class com.duo.test.status.V1_status
Sep 23, 2014 12:23:01 PM com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
Sep 23, 2014 12:23:01 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.17 01/17/2013 03:31 PM'
[2014-09-23 12:23:03 TAKIPI] User code detected.
Sep 23, 2014 12:23:04 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Sep 23, 2014 12:23:04 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Sep 23, 2014 12:23:04 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 6653 ms
OUTPUT:
Upvotes: 3
Views: 23043
Reputation: 66911
It seems when I ran into this it was upgrading jersey from 1.0.2 to 1.1x and the logs would say
INFO: Root resource classes found:
class org.x.y.MyClass
No provider classes found.
And then everything would be a 404, even though it says that the webapp successfully deployed, couldn't get to it at all.
Turns out that my
<servlet-mapping>
<servlet-name>Webapp Human name</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
in web.xml
is no longer good enough for the new version of jersey, it needs to be
<url-pattern>/*</url-pattern>
ref: http://jersey.576304.n2.nabble.com/Jersey-and-url-pattern-td4548025.html
Upvotes: 0
Reputation: 5818
One of the issue, I found with error
com.sun.jersey.api.core.ScanningResourceConfig init INFO: No provider classes found.
is using Lambda expressions(Java 8) in Rest service class. Jersey fails to scan the annotations, if Lambdas are used in the package specified in web.xml file below:
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.duo.test</param-value>
</init-param>
Solution for this problem is to remove Lambda in any class in the package specified.
NOTE: This may be only a problem with Jersey 1.x, I have not tried using Jersey 2.x yet. Removing Lambda has helped me work around the issue temporarily.
Upvotes: 3
Reputation: 32488
URL Mapping was wrong, it should be
<servlet-mapping>
<servlet-name>Jersey Rest Service</servlet-name>
<url-pattern>/v1/*</url-pattern>
</servlet-mapping>
And acording to your configurations, API URL should be http://localhost:8080/v1/status/
Or
Change your URI Mapping in in Service class like
package com.duo.test.status;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
@Path("/api/*")
public class V1_status {
@GET
@Produces(MediaType.TEXT_HTML)
@Path("/v1/status/")
public String returnTitle()
{
return "<p> Java Web Serbice</p>";
}
}
Upvotes: 3