Hi, ich versuche mit ein Eclipse mit Tomcat so zu konfigurieren, dass ich einen REST Service programmieren kann. Leider scheitere ich schon am Hello World Tomcat gibt mir einfach immer einen 404 Error.
Ich poste euch mal ein paar Infos, sind ja nur 2 relevante Files:
[XML]
<?xml version="1.0" encoding="UTF-8"?>
<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>HelloWorld</display-name>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>de.vogella.jersey.first</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
[/XML]
Ich dachte jetzt, dass ich durch http://localhost:8080/HelloWorld/rest/hello zumindest etwas anderes als 404 Error bekommen sollte.
Hat jemand einen Tip fuer mich?
Ich poste euch mal ein paar Infos, sind ja nur 2 relevante Files:
Code:
mathias@id83:~/.workspace/Jersey-HelloWorld$ find .
.
./.project
./src
./src/jersey
./src/jersey/helloworld
./src/jersey/helloworld/Hello.java
./.settings
./.settings/org.eclipse.wst.common.component
./.settings/.jsdtscope
./.settings/org.eclipse.wst.jsdt.ui.superType.name
./.settings/org.eclipse.wst.jsdt.ui.superType.container
./.settings/org.eclipse.wst.common.project.facet.core.xml
./.settings/org.eclipse.jdt.core.prefs
./.classpath
./build
./build/classes
./build/classes/jersey
./build/classes/jersey/helloworld
./build/classes/jersey/helloworld/Hello.class
./WebContent
./WebContent/WEB-INF
./WebContent/WEB-INF/lib
./WebContent/WEB-INF/lib/asm-all-repackaged-2.2.0.jar
./WebContent/WEB-INF/lib/osgi-resource-locator-1.0.1.jar
./WebContent/WEB-INF/lib/javax.inject-2.2.0.jar
./WebContent/WEB-INF/lib/javax.annotation-api-1.2.jar
./WebContent/WEB-INF/lib/jersey-container-servlet.jar
./WebContent/WEB-INF/lib/aopalliance-repackaged-2.2.0.jar
./WebContent/WEB-INF/lib/javax.ws.rs-api-2.0.jar
./WebContent/WEB-INF/lib/jersey-client.jar
./WebContent/WEB-INF/lib/hk2-utils-2.2.0.jar
./WebContent/WEB-INF/lib/jersey-common.jar
./WebContent/WEB-INF/lib/hk2-api-2.2.0.jar
./WebContent/WEB-INF/lib/jersey-guava-2.7.jar
./WebContent/WEB-INF/lib/jersey-container-servlet-core.jar
./WebContent/WEB-INF/lib/hk2-locator-2.2.0.jar
./WebContent/WEB-INF/lib/jaxb-api-2.2.7.jar
./WebContent/WEB-INF/lib/validation-api-1.1.0.Final.jar
./WebContent/WEB-INF/lib/persistence-api-1.0.jar
./WebContent/WEB-INF/lib/jersey-server.jar
./WebContent/WEB-INF/lib/org.osgi.core-4.2.0.jar
./WebContent/WEB-INF/lib/javassist-3.18.1-GA.jar
./WebContent/WEB-INF/lib/javax.servlet-api-3.0.1.jar
./WebContent/WEB-INF/web.xml
./WebContent/META-INF
./WebContent/META-INF/MANIFEST.MF
mathias@id83:~/.workspace/Jersey-HelloWorld$
Java:
package jersey.helloworld;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
// Plain old Java Object it does not extend as class or implements
// an interface
// The class registers its methods for the HTTP GET request using the @GET annotation.
// Using the @Produces annotation, it defines that it can deliver several MIME types,
// text, XML and HTML.
// The browser requests per default the HTML MIME type.
//Sets the path to base URL + /hello
@Path("/hello")
public class Hello {
// This method is called if TEXT_PLAIN is request
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello() {
return "Hello Jersey";
}
// This method is called if XML is request
@GET
@Produces(MediaType.TEXT_XML)
public String sayXMLHello() {
return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey" + "</hello>";
}
// This method is called if HTML is request
@GET
@Produces(MediaType.TEXT_HTML)
public String sayHtmlHello() {
return "<html> " + "<title>" + "Hello Jersey" + "</title>"
+ "<body><h1>" + "Hello Jersey" + "</body></h1>" + "</html> ";
}
}
[XML]
<?xml version="1.0" encoding="UTF-8"?>
<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>HelloWorld</display-name>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>de.vogella.jersey.first</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
[/XML]
Ich dachte jetzt, dass ich durch http://localhost:8080/HelloWorld/rest/hello zumindest etwas anderes als 404 Error bekommen sollte.
Hat jemand einen Tip fuer mich?