maven - Java 1.8, tomcat 8.5, Jersey 2 - Can't make it work -


i went on everything, made changes, fixed problems still server sends 404 though tomcat , running. following did:

pom.xml:

<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">     <modelversion>4.0.0</modelversion>     <groupid>com.resty</groupid>     <artifactid>resty</artifactid>     <version>0.0.1-snapshot</version>     <packaging>war</packaging>     <repositories>         <repository>             <id>maven2-repository.java.net</id>             <name>java.net repository maven</name>             <url>http://download.java.net/maven/2/</url>             <layout>default</layout>         </repository>     </repositories>     <dependencies>         <!-- jax-rs -->         <dependency>             <groupid>javax.ws.rs</groupid>             <artifactid>javax.ws.rs-api</artifactid>             <version>2.0.1</version>         </dependency>                <dependency>             <groupid>org.glassfish.jersey.containers</groupid>             <artifactid>jersey-container-servlet</artifactid>             <version>2.25.1</version>         </dependency>         <dependency>             <groupid>org.glassfish.jersey.core</groupid>             <artifactid>jersey-server</artifactid>             <version>2.25.1</version>         </dependency>         <dependency>             <groupid>org.glassfish.jersey.core</groupid>             <artifactid>jersey-client</artifactid>             <version>2.25.1</version>         </dependency>     </dependencies>     <build>         <finalname>resty</finalname>         <plugins>             <plugin>                   <artifactid>maven-war-plugin</artifactid>                   <version>3.0.0</version>             </plugin>             <plugin>                 <artifactid>maven-compiler-plugin</artifactid>                 <configuration>                     <source>1.8</source>                     <target>1.8</target>                 </configuration>             </plugin>         </plugins>     </build> </project> 

web.xml

<?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_3_0.xsd"     version="3.0">     <display-name>resty</display-name>     <welcome-file-list>         <welcome-file>index.html</welcome-file>         <welcome-file>index.htm</welcome-file>         <welcome-file>index.jsp</welcome-file>         <welcome-file>default.html</welcome-file>         <welcome-file>default.htm</welcome-file>         <welcome-file>default.jsp</welcome-file>     </welcome-file-list>      <servlet>         <servlet-name>jersey-serlvet</servlet-name>         <servlet-class>org.glassfish.jersey.servlet.servletcontainer</servlet-class>         <init-param>              <param-name>jersey.config.server.provider.packages</param-name>              <param-value>com.resty</param-value>         </init-param>         <load-on-startup>1</load-on-startup>     </servlet>      <servlet-mapping>         <servlet-name>jersey-serlvet</servlet-name>         <url-pattern>/resty/*</url-pattern>     </servlet-mapping>  </web-app> 

resty.java

package com.resty;  import javax.ws.rs.get; import javax.ws.rs.path; import javax.ws.rs.pathparam; import javax.ws.rs.produces; import javax.ws.rs.core.mediatype;  @path("/resty") public class resty {      @get     @produces(mediatype.application_json)     @path("/example")     public string getexample() {         return "{\"result\":\"blah\"}";     } } 

i'm sure i'm missing can't figure out is. when run - running on server, eclipse opens url: http://localhost:9090/resty/ see 404. tried adding more resty/ url , /example (see code above) gives 404.

what missing?

you using <url-pattern>/resty/*</url-pattern> in web.xml , using @path("/resty") in class class mapping, , use url http://localhost:9090/resty/ wrong. need use <url-pattern>/*</url-pattern>. , url http://localhost:9090/resty/

you can use <url-pattern>/*</url-pattern> want need use pattern before controller path in url.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -