我已经尝试了非常简单的restful教程与javax.ws和我有问题与maven依赖。 web.xml文件如下正在添加:宁静与maven有404找不到错误
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<servlet>
<servlet-name>jersey-servlet</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>service</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
和Maven依赖这样的:
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>groupId</groupId>
<artifactId>untitled40</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
</project>
和类是:
package service;
import javax.ws.rs.*;
@Path("hesab")
public class App {
@Path("textc")
@GET
@Produces("text/plain")
public String recit(){
return "got it";
}
}
,问题是,当我添加JAR文件到在WEB-INF中的lib文件夹它将工作并连接到我的服务,但是当我尝试添加Maven依赖项和删除lib文件夹时,它不起作用!你能告诉我问题是什么吗?
您的示例pom.xml将生成一个JAR文件 - 不是WAR文件。你需要添加一个' war'元素。 –
我应该添加这个包装?在POM中? – bigelite
是,通常 untitled40 '和' 1.0快照之间'' 我 –