Jetty SERVICE_UNAVAILABLE in Maven WebApp with Jersey JAX-RS in Eclipse
After Trying to run my WebApp Example in Tomcat, not succeeding I followed the this tutorial in order to get a simple HelloWorld JAX-RS application running in Eclipse with Maven. Unfortunately when I execute mvn jetty:run
and open http://localhost:8088/jersey-demo/hello/
in a browser I only get back:
HTTP ERROR: 503
SERVICE_UNAVAILABLE
RequestURI=/jersey-demo/hello
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ele.api</groupId>
<artifactId>server</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>server Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.1</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.13</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.6.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.16</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.7</version>
<type>pom</type>
<scope>compile</scope>
</dependency>
</depe开发者_如何学Cndencies>
<repositories>
<repository>
<id>maven2-repository.java.net</id>
<name>Java.net Repository for Maven</name>
<url>http://download.java.net/maven/2/</url>
<layout>default</layout>
</repository>
<repository>
<id>maven-repository.java.net</id>
<name>Java.net Maven 1 Repository (legacy)</name>
<url>http://download.java.net/maven/1</url>
<layout>legacy</layout>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<!-- JETTY 6 PLUGIN -->
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.14</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<contextPath>/jersey-demo</contextPath>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>8088</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
<webApp>${basedir}/target/jersey-demo</webApp>
<requestLog implementation="org.mortbay.jetty.NCSARequestLog">
<filename>target/yyyy_mm_dd.request.log</filename>
<retainDays>90</retainDays>
<append>true</append>
<extended>true</extended>
<logTimeZone>GMT</logTimeZone>
</requestLog>
</configuration>
</plugin>
</plugins>
</build>
</project>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>Jersey Demo</display-name>
<servlet>
<servlet-name>ServletAdaptor</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.ele.api</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ServletAdaptor</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
MyServlet.java in src/main/resources
package com.ele.api
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.apache.log4j.Logger;
/**
* Jersey Demo
*/
@Path("/hello")
public class MyServlet {
private static final Logger LOGGER = Logger.getLogger(MyServlet.class);
/**
*
* @return
*/
@GET
@Produces("text/plain")
public String doGet() {
return "hello";
}
/**
*
* @param xml
* @return
*/
@POST
@Produces("application/xml")
@Consumes({"application/x-www-form-urlencoded", "multipart/form-data"})
public String doPost(@FormParam("xml") String xml) {
if(xml == null) {
LOGGER.error("Expected 'xml' parameter was not found in the POST");
return null;
}
return xml;
}
Remove the entry from artifact jersey-server and it should work.<type>pom</type>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.7</version>
<scope>compile</scope>
</dependency>
In Eclipse, goto Windows
-> Preferences
-> Maven
-> User Settings
and make sure you have point settings.xml
file under your .m2
directory there.
Also check the second second field Local Repository
has correct repository address.
精彩评论