I am a total newbiew to the JAX-RS rest api and tyring to use the jersey library for the same. I have the below configuration :
Netbeans 8.0.2 and Tomcat 7 installed (externally).
I have registered the tomcat7 server in Netbeans:
I have created a new maven project with the archtype of jersey and just try to run the default project of webapi/myresource to give me back the simple text back..
this is my default 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>
Have also mentioned that this project be deployed on tomcat7
My project builds:
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=/
Nothing happens , i assume my browser must open , but i am missing something here that i cannot seem to get my head around :(
If you are using Tomcat 7, set the version of the servlet api to 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">
should be:
<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">
Note that the version needs to be set a two positions. The metadata-complete attribute makes sure that annoation scanning will be invoked, which should find your classes.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.