0

I am trying to access a resource on my Hello world (for now) application. However, I get this HTTP status 404 - not found when I deploy it ot Tomcat and hit the URL: localhost:8080/test/rest. Here are my pom.xml depdendencies:

<dependency> <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-common</artifactId> <version>2.26-b03</version> </dependency> <dependency> <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-server</artifactId> <version>2.26-b03</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> </dependency> <dependency> <groupId>org.glassfish.jersey.containers</groupId> <artifactId>jersey-container-servlet</artifactId> <version>2.26-b03</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> 

And here are my web.xml configurations:

<web-app> <display-name>Archetype Created Web Application</display-name> <servlet> <servlet-name>HelloWorld Jersey 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 >com.latin.translator.app</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name >HelloWorld Jersey Service </servlet-name > <url-pattern >/test/*</url-pattern > </servlet-mapping> </web-app> 

The java code is:

@Path("/test") public class Test { @GET @Produces(TEXT_PLAIN) @Path("/rest") public String test() { return "Great success"; } } 

Do you have any ideas what I am doing wrong?

1
  • Whats the context name of the web app deployed? Commented Jul 18, 2018 at 6:25

3 Answers 3

2

TRy localhost:8080/test/test/rest

<servlet-mapping> <servlet-name >HelloWorld Jersey Service </servlet-name > <url-pattern >/test/*</url-pattern > </servlet-mapping> 

This says root is test so url is localhost:8080/test/ for jesrsey

Now

@Path("/test") public class Test { 

says now next url path is test so url is localhost:8080/test/test

@Path("/rest") public String test() { return "Great success"; } 

says /rest as next url so its localhost:8080/test/test/rest

Sign up to request clarification or add additional context in comments.

Comments

0

You need to extend the javax.ws.rs.core.Application class.

@ApplicationPath("/") // the context root of you application public class JaxRsConfig extends Application { private final Set<Class<?>> classes; public JaxRsConfig() { HashSet<Class<?>> c = new HashSet<>(); c.add(Test.class); //repeat for all JAX-RS classes in your application classes = Collections.unmodifiableSet(c); } @Override public Set<Class<?>> getClasses() { return classes; } } 

With this you do not need a web.xml file.

Comments

-1

As there is a provider package specified so you can try with the following url-localhost:8080/com.latin.translator.app/test/rest

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.