我对JAX-RS rest api和tyring的全面了解,以便使用jersey-library。我有以下配置:
安装了Netbeans 8.0.2和Tomcat 7(外部)。
我用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>
我的项目构建:
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=/
没有任何反应,我认为我的浏览器必须打开,但我在这里遗漏了一些我似乎无法理解的东西:(
答案 0 :(得分:0)
如果您使用的是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属性确保将调用annoation扫描,这应该找到您的类。