I've inherited an application that runs on a JBoss 4.2.1.GA deployment cluster. The application is a hybrid of technologies, but the primary View technologies used are Struts 1 & Struts 2 (they co-exist).
I am struggling with understand how the application is built and deployed. The app using i18n for the front end, and uses the standard bean:message tags to retrieve the translations:
Ex:
<%# taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<input type="text" name="searchFilter" id="searchFilterId" value="<bean:message key="ng.searchfor"/>"
Additionally, the app has a bunch of application.properties files (for each translation).
However, when the EAR is built and deployed, the application*.properties files are not packaged in the WAR/EAR. Rather they are stripped and copied to an external shared folder on the server (one to which all the nodes in the cluster have access). The concept, I believe, is that the properties can be written to a central location, and loaded/reloaded on the fly by the application.
I don't understand, however, how struts manages to load these translation files. From my understanding, the application*.properties files need to be on the application classpath such that struts can find them.
The struts-config.xml file has no additional information:
Nor does the web.xml:
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>chainConfig</param-name>
<!-- We overide the default chain-config.xlm file to add the chain command in charge of the audit trail.-->
<param-value>/WEB-INF/chain-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
So my only conclusion is that somehow these application.properties file (stored in a path external to jboss) is mapped to the classpath somehow such that the classloader can automatically find them.
But I can't seem to find that directive/configuration instruction anywhere.
Does JBoss 4 have a config file that would allow me to add paths to the classloader? I found references to using modules in JB 7+, but haven't been able to find anything for JB4. Or is there a way to configure struts to load it's application.properties files from outside the classpath?
I am following this tutorial to create a REst Service using Jersey.
Sometimes i fail to understand fully what the author of the tutorial means but these are the steps that i have followed so far :
1) Created a dynamic web project and named it : de.vogella.jersey.first
2) Installed Maven dependencies on eclipse
3) Converted my project to a Maven project (that means created a pom.xml file)
4) Added the necessary dependencies in pom.xml so that i can use jersey without having to manually add the jar files. I added the following xml :
<dependencies>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.17.1</version>
</dependency>
</dependencies>
5) The author suggests to create a java class and gives some code. I can only assume that he wants us to create a new package in the src folder , name it de.vogella.jersey.first and then create a java class and name it Hello and place the code there. Thats what i did.
6) Then he suggests to open the web.xml file. Theres not such a file in the project though. So i go ahead and create such a file in the WebContent/WEB-INF/lib path. I place the code that he suggest.
7) Next is the step that i fail to understand most. He talks about the web.xml that we just added and more specifically he states:
"The parameter "com.sun.jersey.config.property.package" defines in which package jersey will look for the web service classes. This property must point to your resources classes. "
8) Last step is open the URL http://localhost:8080/de.vogella.jersey.first/rest/hello in my browser. However i get HTTP Status 404 - /de.vogella.jersey.first/rest/hello
With what shall i replace exactly the com.sun.jersey.config.property.package ?
Are the steps that i have followed till now correct , or i misinterpreted something?
For information if you are using Jersey 2 this class has been replaced with jersey.config.server.provider.packages so your resource configuration would be like:
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>de.vogella.jersey.todo.resources</param-value>
</init-param>
The property com.sun.jersey.config.property.package just needs to be set as the package that contains the web service classes. In the tutorial it is de.vogella.jersey.first, and you can see that the Hello class is declared under that package.
In other words, when you deploy the application, Jersey will look for web service classes in the package de.vogella.jersey.first, and in this case it will find the class Hello being declared with the javax.ws.rs.Path annotation, and create a web service endpoint listening on the URL that has been declared with #Path.
However, I have never set such a thing for my Jersey projects. I just put my web service classes in the src folder, and Jersey recognizes them no matter which package I put them inside. This is the minimum configuration that I have with Jersey projects in web.xml:
<servlet>
<description>JAX-RS Tools Generated - Do not modify</description>
<servlet-name>JAX-RS Servlet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<!--
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.your.webservice.classes</param-value>
</init-param>
-->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JAX-RS Servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
Also if you do not fancy Maven projects, just create a simple Dynamic Web Project and copy the Jersey JARs to WebContent/WEB-INF/lib.
Also, as Qwerky suggested, web.xml has to be in WebContent/WEB-INF/ and .jar files should be copied to WebContent/WEB-INF/lib.
Other than that, the described procedure looks fine!
I've just started building my own rest webservice and I started off by going through this excellent tutorial: http://www.vogella.com/articles/REST/article.html#first_project
However there is something that I don't quite understand. It has to do with the path to the service.
The path is now this for the hello resource:
http://localhost:8080/de.vogella.jersey.first/rest/hello
This is default from the tutorial.
However i would like to change this to a more convenient link, for example like this:
http://localhost:8080/mywebservice/resources/hello
I change the web.xml to the following as a try to achieve it:
<?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>mywebservice</display-name>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.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>/resources/*</url-pattern>
</servlet-mapping>
</web-app>
I changed the display name and the url-pattern but it has no effect. I cant get to the resource using the path I want it to be, though I can retrieve it from the old path.
Why is that? Does the displayname from the web.xml got nothing to do with this?
You are changing the context name of the Webapp. If you're deploying it in the form of a war (webapp archive), the name of the war would be the context name.
In the example you're following, you're creating a Dynamic Web project with that name. You'll have to rename it suitably.
Same problem here.
I tried to change the "display-name", but it does not affect the service-URL at all.
A change in "url-pattern", though, DID change the URL.
So from the "first REST example" from Vogella, I'd say, the URL is initially built as follows:
http:// your_domain:port/**project-name**/url-pattern/path_from_rest_class
Greetings
Jana
ADDITION: SOLUTION
Meanwhile I found out a way to change this very part of the URL (the "display name"):
You go to the application.xml of your EAR project (folder META-INF)
--> if no xml is there, right-click the node "deployment descriptor" and chose "Generate Deployment Descriptor Stub", it creates application.xml))
For altering the URL-part "display name" you have to change the value in "context root".
(the "web-uri" must not be changed!)
now the URL pattern is as follows:
http:// your_domain:port/**context-root**/url-pattern/path_from_rest_class
So you CAN change the URL the way you like. :-) Hope this helps!
Greetings
Jana
Another way to do this is that you right click on your project and goto WebProject settings from where you can change the Context root same as whatever you want in displayName too and then run project again on server.
This worked for me as issue was only with displayName because works fine when we change it for accessing with new URI.
Thanks
What's going wrong here?
The ResourceConfig instance does not contain any root resource classes.
Dec 10, 2010 10:21:24 AM com.sun.jersey.spi.spring.container.servlet.SpringServlet initiate
SEVERE: Exception occurred when intialization
com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.
at com.sun.jersey.server.impl.application.RootResourceUriRules.<init>(RootResourceUriRules.java:103)
at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1182)
at com.sun.jersey.server.impl.application.WebApplicationImpl.access$600(WebApplicationImpl.java:161)
at com.sun.jersey.server.impl.application.WebApplicationImpl$12.f(WebApplicationImpl.java:698)
at com.sun.jersey.server.impl.application.WebApplicationImpl$12.f(WebApplicationImpl.java:695)
at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:197)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:695)
at com.sun.jersey.spi.spring.container.servlet.SpringServlet.initiate(SpringServlet.java:117)
Filter:
<filter>
<filter-name>JerseyFilter</filter-name>
<filter-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</filter-class>
<init-param>
<param-name>com.sun.jersey.config.feature.Redirect</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.property.JSPTemplatesBasePath</param-name>
<param-value>/views/</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.property.WebPageContentRegex</param-name>
<param-value>/(images|css|jsp)/.*</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>JerseyFilter</filter-name>
<url-pattern>/myresource/*</url-pattern>
</filter-mapping>
Code:
#Path ("/admin")
public class AdminUiResource {
#GET
#Produces ("text/html")
#Path ("/singup")
public Viewable getSignUp () {
return new Viewable("/public/signup", "Test");
}
}
Have you tried adding
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>my.package.name</param-value>
</init-param>
to your SpringServlet definition? Obviously replace my.package.name with the package that AdminUiResource is in and make sure it is in the classpath.
I am new to Jersey - I had the same issue, But when I removed the "/" and just used the #path("admin") it worked.
#Path("admin")
public class AdminUiResource { ... }
YOU NEED TO ADD YOUR PACKAGE NAME AT
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>your.package.name</param-value>
</init-param>
ALSO ONE SILLY THING I HAVE NOTICED,
I Need to refresh my project after MAVEN BUILD else it show me same error.Please comment If you know reason why we need to refresh project?
This means, it couldn't find any class which can be executed as jersey RESTful web service.
Check:
Whether 'com.sun.jersey.config.property.packages' is missing in your
web.xml.
Whether value for 'com.sun.jersey.config.property.packages'
param is missing or invalid (the mentioned package doesn't exists). It should be a package where you have put your POJO classes which runs as jersey services.
Whether there exists at least one POJO class, which has a method annotated with #Path attribute.
Your resource package should contain at least one pojo which is either annotated with #Path or have at least one method annotated with #Path or a request method designator, such as #GET, #PUT, #POST, or #DELETE. Resource methods are methods of a resource class annotated with a request method designator. This resolved my issue...
I ran across this problem with JBOSS EAP 6.1. I was able to deploy my code through eclipse to the JBOSS server but once I attempted to deploy the file as a WAR file to JBOSS I started getting this error.
The solution was configuring the web.xml to work properly with JBOSS by allowing the two to work together.
The following two lines were commented out in web.xml to allow JBOSS to do it's own configurations
<!--
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.your.package</param-value>
</init-param> -->
And then add the following context params after
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>resteasy.scan.resources</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>resteasy.scan.providers</param-name>
<param-value>false</param-value>
</context-param>
Basically I corrected it like below and everything worked fine.
<servlet>
<servlet-name >MyWebApplication</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.feature.Redirect</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.property.JSPTemplatesBasePath</param-name>
<param-value>/views/</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.property.WebPageContentRegex</param-name>
<param-value>/(images|css|jsp)/.*</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>MyWebApplication</servlet-name>
<url-pattern>/myapp/*</url-pattern>
</servlet-mapping>
I am getting this exception, because of a missing ResourseConfig in Web.xml.
Add:
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>/* Name of Package where your service class exists */</param-value>
</init-param>
Service class means: class which contains services like: #Path("/orders")
I had the same issue with trying to run the webapp from an eclipse project. As soon I copied the .class files to /WEB-INF/classes it worked perfectly.
I had the same issue, testing a bunch of different examples, and tried all the possible solutions. What finally got it working for me was when I added a #Path("") over the class line, I had left that out.
Had the same issue and found out it was a problem with the way I deployed my source code. As the error message says: "...does not contain any root resource classes". So it couldn't find any resource classes in the configured package. I just deployed the classes wrong - that's why it didn't pick it up.
I forgot to deploy my class files in the /WEB-INF/classes directory of the WAR - initially I just had it directly in the root of the WAR file. So when it looked for resource classes it didn't find them - because they existed in a different (wrong) location.
Same issue - web.xml looked like this:
<servlet>
<servlet-name>JerseyServlet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.mystuff.web.JerseyApplication</param-value>
</init-param>
...
Providing a custom application overrides any XML configured auto detection of classes. You need to implement the right methods to write your own code to wire up the classes. See the javadocs.
Another possible cause of this error is that you have forgotten to add the libraries that are already in the /WEBINF/lib folder to the build path (e.g. when importing a .war-file and not checking the libraries when asked in the wizard). Just happened to me.
It happened to me when I deployed my main.jar, without checking the add directory entries box in the export jar menu in Eclipse.
Well, it's a little late to reply. I have faced the same problem and my Google searches were in vain. However, I managed to find what the problem was. There might be many reasons for getting this error but I got the error due to the following and I wanted to share this with my fellow developers.
I previously used Jersey 1.3 and I was getting this error. But when I upgraded the jars to the latest version of Jersey, this issue was resolved.
Another instance in which I got this error was when I was trying to deploy my service into JBoss by building a war file. I made the mistake of including the Java files in the .war instead of java classes.
I had to add a trailing forward slash to the end of #path
#Path ("/admin/")
Ok... For me work fine just only assigning the "servlet-class" to com.sum.jersey.spi.container.servlet.ServletContainer, I am using IDE (Eclipse Mars)
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/frontend/*</url-pattern>
</servlet-mapping>
but for some reason I had to reboot my computer in order to work in my localhost. If still not work? You have to add in your web.xml this code in between "servlet" tag.
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>the.package.name</param-value>
</init-param>
"the.package.name" is the package name where you have your classes. If you are using IDE, refresh the project and run again in Tomcat. still not work? reboot your computer and will work.
Another thing to check is a combination of previous entries
You can have in your web.xml file this:
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.acme.rest</param-value>
</init-param>
and you can have
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>resteasy.scan.providers</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>resteasy.scan.resources</param-name>
<param-value>false</param-value>
</context-param>
but you cannot have both or you get this sort of error. The fix in this case would be to comment out one or the other (probably the first code snippet would be commented out)
yes adding the init param for com.sun.jersey.config.property.packages fixed this issue for me.
was merging a jersey rest services into maven based spring application and got this error.
I also got this kind of error, please take care of the configurations in xml.
I wrote
com.sun.jersey.comfig.property.packages
Instead of
com.sun.jersey.config.property.packages
After correction it's working.
that issue is because jersey can't find a dependecy package for your rest
service declarated
check your project package distribution and assert that is equals to your web.xml param value
Probably too late but this is how I resolved this error.
If this solution is not working,
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>/* Name of Package where your service class exists */</param-value>
</init-param>
In eclipse:
RightClick on your Project Or Select Project and press Alt + Enter On the left-hand side of the opened window find Java Build Path
Select Libraries from the right tab panel: If there is anything which is corrupted or showing cross mark on top of the jars, remove and add the same jar again
Apply and Close
Rebuild your project
In my case I have added the jars twice in build path after importing from war.
It worked fine after removing the extra jars which was showing error deployment descriptor error pages
adding
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>service.package.name</param-value>
</init-param>
Also came accross this problem, twice for different reasons. The first time I forgot to include
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>my.package.name</param-value>
</init-param>
as described in previous comments, and once I did that, it started working.
Yet... another day I started Eclipse, expecting to continue where I left off, and instead of having my program working, it showed the very same error once again. I started checking if I accidentally had made some changes and saved corrupted file, but could find no such error and the file looked exactly like examples I have, all in order. Since it worked the day before, after some initial searching, I thought, well, maybe it's a Eclipse, or Tomcat glitch or something, so let's just try to make some changes and see if it reacts. So, I did a space + backspace in web.xml file, just to fool Eclipse that the file is changed, and saved it then. The next step was restarting Tomcat server (from Eclipse IDE) and voila, it works again!
Maybe someone with broader experience could explain what the problem really was behind all of this?
Main cause of this Exception is:
You have not given the proper package name where you using the #Path or forgot to configure in web.xml / Configuration file(Rest API Class File package Name, Your Class Package Name)
Check this Configuration inside <init-param>