【问题标题】:Jersey web application not deploying on tomcatJersey Web应用程序未部署在tomcat上
【发布时间】:2015-11-13 14:09:35
【问题描述】:

我是 JAX-RS rest api 的新手,并且很想使用 jersey 库。我有以下配置:

已安装 Netbeans 8.0.2 和 Tomcat 7(外部)。

我已经在 Netbeans 中注册了 tomcat7 服务器:

我已经使用 jersey 的 archtype 创建了一个新的 maven 项目,并尝试运行 webapi/myresource 的默认项目以将简单的文本返回给我..

这是我的默认 web.xml

    <?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is not required when using Servlet 3.0 container,
     see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html -->
<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">
    <servlet>
        <servlet-name>Jersey Web Application</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>edu.kit.nanoscopy.metadata.metadatagmf</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Jersey Web Application</servlet-name>
        <url-pattern>/webapi/*</url-pattern>
    </servlet-mapping>
</web-app>

也提到过这个项目部署在tomcat7上

我的项目构建:

NetBeans: Deploying on Apache Tomcat or TomEE
    profile mode: false
    debug mode: false
    force redeploy: true
In-place deployment at /home/anil/NetBeansProjects/MetadataGMF/target/MetadataGMF
Deployment is in progress...
deploy?config=file%3A%2Ftmp%2Fcontext8728006981910574558.xml&path=/
http://localhost:8080/manager/text/deploy?config=file%3A%2Ftmp%2Fcontext8728006981910574558.xml&path=/

什么都没有发生,我认为我的浏览器必须打开,但我在这里遗漏了一些我似乎无法理解的东西:(

【问题讨论】:

    标签: java maven tomcat netbeans


    【解决方案1】:

    如果您使用的是 Tomcat 7,请将 servlet api 的版本设置为 3.0:

    <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">
    

    应该是:

    <web-app version="3.0" metadata-complete="false" 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_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID">
    

    注意,版本需要设置两个位置。 metadata-complete 属性确保将调用注释扫描,这应该会找到您的类。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-10
      • 2015-05-20
      • 1970-01-01
      • 2022-11-11
      • 2011-01-14
      • 2012-06-23
      相关资源
      最近更新 更多