如何摆脱这个错误:“WEB-INF \ lib \ javax.servlet-api-3.0.1.jar) - jar未加载。请参阅Servlet规范2.3,第9.7.2节。”

时间:2017-02-01 06:45:21

标签: java web-services servlets jboss netbeans-8

我正在尝试通过引用此网站来创建简单的网络服务:http://www.connect2java.com/webservices/jax-rs-applicationpath-annotationno-web-xml-example-in-jersey/

我正在使用

  

NetBeans IDE 8.0.2

     

Java 8.0 JDK 1.7

     

JBoss服务器

这是我的代码:

RestfulApplicationPathAnnotationExample.java:

package com.connect2java.RestfulApplicationPathAnnotationExample;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

@Path("/hello")
public class RestfulApplicationPathAnnotationExample {
    @GET
    @Produces(MediaType.TEXT_HTML)     
     public Response sayHello() {

        String str ="<H1>Hi!!! welcome to @ApplicationPath Annotation Example in Restful webservices  </H1> ";

        return Response.status(200).entity(str).build();

    }

}

MyApplication.java:

package com.connect2java.RestfulApplicationPathAnnotationExample;

import javax.ws.rs.ApplicationPath;

import org.glassfish.jersey.server.ResourceConfig;

    @ApplicationPath("resources")
    public class MyApplication extends ResourceConfig {
        public MyApplication() {
            packages("com.connect2java.RestfulApplicationPathAnnotationExample");
        }

    }

的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">
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

运行输出:

run output

服务器上显示

错误:

13:06:39,832 INFO  [TomcatDeployer] undeploy, ctxPath=/RestfulApplicationPathAnnotationExample, warUrl=.../tmp/deploy/tmp7253522143789622225RestfulApplicationPathAnnotationExample-exp.war/
13:06:40,253 INFO  [TomcatDeployer] deploy, ctxPath=/RestfulApplicationPathAnnotationExample, warUrl=.../tmp/deploy/tmp3990284126749515271RestfulApplicationPathAnnotationExample-exp.war/
13:06:40,316 INFO  [WebappClassLoader] validateJarFile(C:\jboss\server\default\.\tmp\deploy\tmp3990284126749515271RestfulApplicationPathAnnotationExample-exp.war\WEB-INF\lib\javax.servlet-api-3.0.1.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class

计划结构:

enter image description here

我在此网址的网页上显示“Hello World”输出:

  

http://localhost:8080/RestfulApplicationPathAnnotationExample/

但是当我尝试这个网址时:

  

http://localhost:8080/RestfulApplicationPathAnnotationExample/resources/hello

我收到此错误消息:

HTTP Status 404 - /RestfulApplicationPathAnnotationExample/resources/hello

The requested resource (/RestfulApplicationPathAnnotationExample/resources/hello) is not available.

有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:0)

  

WEB-INF \ lib \ javax.servlet-api-3.0.1.jar) - jar未加载。请参阅Servlet规范2.3,第9.7.2节。“

这是一个警告(不是错误)。您不应该部署任何包含javax.servlet类的jar。容器会忽略它。只需从javax.servlet-api-3.0.1.jar

中删除.war即可

关于你的路径问题,似乎球衣遗漏了@ApplicationPath("resources")。尝试添加/前缀here @ApplicationPath("/resources")