I'm trying to deploy a simple web application under JBoss AS 7.1 which comes bundled with resteasy. According to the documentation all that is needed is (at bare minimum) is an empty web.xml
, a class with annotated @ApplicationPath("/mypath")
and @Path("/other_stuff")
for your other classes
The documentation I'm following is here:
- https://docs.jboss.org/author/display/AS7/JAX-RS+Reference+Guide
- https://docs.jboss.org/author/display/AS7/Java+API+for+RESTful+Web+Services+(JAX-RS)
Still, when I hit:
host:8080/warname/applicationpath/path
I receive a 404 error on the webpage but nothing in the logs.
Is there a configuration file I need to change in order for JAX-RS to work?
Thank you in advance for any help!
Empty
web.xml
will do.Just add some resteasy dependency to your classpath. For instance, if you use maven you can add this to your
pom.xml
:Then set up the application using only this class:
Just to make sure, add a resource like this:
And that's all you need. Deploy it at a JBoss AS 7.1 and get to it, say:
Edit:
I have created a java war maven project with the bare minimum strucutre:
I called it
simpleRest
as seen below. All the archives are exactly as shown:pom.xml:
HelloResource.java
JaxRsActivator.java:
This generates a
simpleRest.war
(throughmvn clean package
). I then deploy it to a freshly installed JBoss AS 7.1.1.Final. As you can see, no reference is made to JAX-RS in the log during the deploy:After that, the URL is available as expected:
Notice that everything else gives a 404 error. But it is a different kind of 404.
http://127.0.0.1:8080/simpleRest/
gives:That is a page not found error. On the other hand,
http://127.0.0.1:8080/simpleRest/rest
gives:That is a resource (REST service) not found error. This way you know JAX-RS is acting, though it did not have a handler for that path.
Take a look at jboss quickstarts: http://www.jboss.org/jdf/quickstarts/jboss-as-quickstart/ You can get them from http://www.jboss.org/jbossas/downloads
These are working out of box. For helloword-rs quickstart I can see web.xml with content:
and also comment: One of the way of activating REST Servises is adding these lines, the server is responsible for adding the corresponding servlet automatically. If the src folder, org.jboss.as.quickstarts.rshelloworld.HelloWorld class has the Annotations to receive REST invocation.
Even though acdcjunior's answer is great and very thorough, i'd like to reinfoce Andrzej's answer.
It works as a charm and it is by far the more straightforward one. The JBoss quickstart samples (also available on GitHub) are always a great resource to answer questions like this one.
If you are using JBoss AS 7.1, you also need to add the "resteasy.resources" context parameter. You also need to send the init-param to the HttpServletDispatcher servlet.
I found the solution at the following link : http://www.javaroots.com/2013/05/creating-rest-services-with-rest-easy.html
Just one typo error(maybe!!) in the above link. In the "RootRestService" change the method signature of the getClasses() method to
public Set<Class<?>> getClasses()
.Thats it! It solved my 3 day headache. Hope it helps you too!! :)