0

I'm with this test project named CLAWS-Dicionario, and I'm trying to run it on Glassfish server (which is working flawlessly). All I have is that class:

package com.k19.restful.resources; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; @Path("/helloworld") public class HelloWorldResource { @GET @Produces("text/plain") public String showHelloWorld() { return "Olá mundo!"; } } 

And this add at web.xml in order to incorporate Jersey to it

<servlet> <servlet-name>Jersey REST Service</servlet-name> <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> <init-param> <param-name>com.sun.jersey.config.property.packages</param-name> <param-value>com.k19.restful.resources</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Jersey REST Service</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> 

I've also added the following jersey libraries to my build-path:

asm-debug-all-5.0.3.jar javax.ws.rs-api-2.0.1.jar jersey-server.jar org.osgi.core-4.2.0 

So I run the project, and everything feels fine. But when I try to access this URL:

http://localhost:8080/CLAWS-Dicionario/helloworld 

It returns a 404 error. I'm sure the host is congured at 8080 port (the URL localhost:8080 works just fine). So what is the problem?

EDIT: The server began to present another problems, which took me to that line of the domain.xml file:

 <application context-root="/CLAWS_-_Dicionário" object-type="user" name="CLAWS-Dicionario" directory-deployed="true" location="${com.sun.aas.instanceRootURI}/eclipseApps/CLAWS-Dicionario/"> 

Repare the CLAWS_-_Dicionário part. Would this be the real name of my project? I had to remove the accent in order the server to work, and I'm finding no more console response when running the project...and even if I try the URL http://localhost:8080/CLAWS_-_Dicionario/helloworld, the error is still there,so...just found it something important to point.

3
  • Your project path might be wrong. Check your logs to find out if it is actually CLAWS-Dicionario or just something similar (eg. you named your project "claws", or "demo" or something). Commented Aug 17, 2015 at 19:24
  • Where in the log file? Found nothing there very useful. PS: please see the edit. Commented Aug 17, 2015 at 23:27
  • From your edit the context root is the path of your application. Try context-root="/CLAWS-Dicionario" and localhost:8080/CLAWS-Dicionario/helloworld Commented Aug 17, 2015 at 23:47

1 Answer 1

1

Depending on which Servlet version you use, you need:

For Servlet 2.x implementation:

  • jersey-container-servlet-core.jar

For Servlet 3.x implementation:

  • jersey-container-servlet.jar

org.glassfish.jersey.servlet.ServletContainer is not packaged in jersey-server.jar

According to the api doc for Class ServletContainer

If the initialization parameter is not present and a initialization parameter "jersey.config.server.provider.packages" is present (see ServerProperties.PROVIDER_PACKAGES) a new instance of ResourceConfig with this configuration is created. The initialization parameter "jersey.config.server.provider.packages" MUST be set to provide one or more package names. Each package name MUST be separated by ';'.

The parameter com.sun.jersey.config.property.packages have been replaced by jersey.config.server.provider.packages in version 2.x.

<init-param> <param-name>jersey.config.server.provider.packages</param-name> <param-value>com.k19.restful.resources</param-value> </init-param> 

In domain.xml, you should have the context-root representing the url path from where the application is accessible:

<application context-root="/CLAWS-Dicionario" object-type="user" name="CLAWS-Dicionario" directory-deployed="true" location="${com.sun.aas.instanceRootURI}/eclipseApps/CLAWS-Dicionario/"> 

letting you access your application from:

 http://localhost:8080/CLAWS-Dicionario/helloworld 
Sign up to request clarification or add additional context in comments.

2 Comments

It worked! Thanks! I 'm going to listen some 80 hits to celebrate now!
Well have fun, It was a pleasure!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.