Java – Jersey 2.7 has problems running on Apache Tomcat 7.0
•
Java
I am using Apache Tomcat 7.0 and eclipse to create a sweatshirt application
import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; // Plain old Java Object it does not extend as class or implements // an interface // The class registers its methods for the HTTP GET request using the @GET annotation. // Using the @Produces annotation,it defines that it can deliver several MIME types,// text,XML and HTML. // The browser requests per default the HTML MIME type. //Sets the path to base URL + /hello @Path("/hello") public class Hello { // This method is called if TEXT_PLAIN is request @GET @Produces(MediaType.TEXT_PLAIN) public String sayPlainTextHello() { return "Hello Jersey"; } // This method is called if XML is request @GET @Produces(MediaType.TEXT_XML) public String sayXMLHello() { return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey" + "</hello>"; } // This method is called if HTML is request @GET @Produces(MediaType.TEXT_HTML) public String sayHtmlHello() { return "<html> " + "<title>" + "Hello Jersey" + "</title>" + "<body><h1>" + "Hello Jersey" + "</body></h1>" + "</html> "; } }
web. The XML file is also created as follows:
<?xml version="1.0" encoding="UTF-8"?> <web-app 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_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>de.vogella.jersey.first</display-name> <servlet> <servlet-name>Jersey REST Service</servlet-name> <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> <init-param> <param-name>jersey.config.server.provider.packages</param-name> <param-value>de.vogella.jersey.first</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Jersey REST Service</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping> </web-app>
The following jar files have been added to the Lib folder in Web inf, and after deploying the war file, they also enter the directory structure in the web application
Once I start the Tomcat and war files, the following error displays:
I have added the following jar to the Lib folder:
**/de.vogella.jersey.first/WebContent/WEB-INF/lib/guava-16.0.1.jar /de.vogella.jersey.first/WebContent/WEB-INF/lib/jersey-client.jar /de.vogella.jersey.first/WebContent/WEB-INF/lib/jersey-common.jar /de.vogella.jersey.first/WebContent/WEB-INF/lib/jersey-container-servlet-core.jar /de.vogella.jersey.first/WebContent/WEB-INF/lib/jersey-container-servlet.jar /de.vogella.jersey.first/WebContent/WEB-INF/lib/jersey-server.jar**
But this mistake is still there. Please tell me where I was wrong
Solution
It's finally settled Please check the jar file below Using this number of jar files to implement rest services is disgusting Maybe restlet or easy rest is better than jerseys
hk2-api-2.2.0.jar hk2-locator-2.2.0.jar hk2-utils-2.2.0.jar javassist-3.18.1-GA.jar javax.annotation-api-1.2.jar javax.inject-2.2.0.jar javax.ws.rs-api-2.0.jar jersey-client.jar jersey-common.jar jersey-container-servlet.jar jersey-container-servlet-core.jar jersey-guava-2.8.jar jersey-server.jar,validation-api-1.1.0.Final.jar
I hope someone may find this useful The above is known to use Jersey version 2.8
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码