Servlet exception in java - java

I imported a java project(war file) to eclipse. When I tried to run it , I got following error :
java.lang.Error: Unresolved compilation problems:
The type List is not generic; it cannot be parameterized with arguments <User>
Syntax error, parameterized types are only available if source level is 5.0
I tried to google it. I found that I have to change compliance settings. I changed the compiler compliance level to 5 but it did not solve the problem. Can anybody help me to solve this problem? Thanks in advance.

There are two things you might have to take care of.
The compiler setting.
The runtime setting.
I guess you should have taken care of (1). What you may have missed is the second one. When you try to run that war file, go to "Run As" --> "Run configurations". There you can select the Java version. I assume this is the place you are having an issue. Try setting it to Java 1.5 or higher.
http://img638.imageshack.us/img638/8845/runconfig.jpg

Check java version for your servlet container. You can check Java version in shell by typing
java -version
If its not 1.5+ point to relevant JDK of higher version..

That war is using 'generics' somewhere. and generics is only available with java 5 and above thats the error is saying
please check your java compiler level

The first step to resolving this issue, is to completely ignore the hint "-source 1.5 to enable generics". That message will take you nowhere! The reason being that it originates from the javac compiler, while you need to configure the jasper JSP compiler. This is fortunately quite easy, although finding out on the Tomcat site is quite convoluted. All you need to do is to edit your TOMCAT_INSTALL\conf\web.xml. Add to the org.apache.jasper.servlet.JspServlet the following lines
<init-param>
<param-name>compilerSourceVM</param-name>
<param-value>1.5</param-value>
</init-param>
<init-param>
<param-name>compilerTargetVM</param-name>
<param-value>1.5</param-value>
</init-param>
such that the servlet looks something like the following
[web.xml]
<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>fork</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>xpoweredBy</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>compilerSourceVM</param-name>
<param-value>1.5</param-value>
</init-param>
<init-param>
<param-name>compilerTargetVM</param-name>
<param-value>1.5</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>
You have now configured your Tomcat JSP server...
Configuring Eclipse
The EE edition of Eclipse has a nice feature of enabling you to create a Dynamic web project - essentially an exploded war file and manage the server instance for you and set up debugging. Convenient once you know how it works. Basically what the standard setup does, is that it copies the Tomcat configuration files from your install directory onto some obscure path similar to c:\workspace.metadata.plugins\org.eclipse.wst.server.core\tmp0\conf\ The first thing to realize is that it copies the files from your installed Tomcat directory quite frequently, so editing your web.xml in this directory as instructed above will only work for a short time.
You may also try editing the web.xml under the Servers project Eclipse installs when you setup your first server. I had a very hard time making Eclipse pick up changes in this file..
Instead, simply delete your server instance and re-create it. Your changes will now have been picked up and you are ready to go!

Related

Stripes 1.6 missing SpringInterceptor

Just upgraded an application from Stripes version 1.5.7 to 1.6.0, but it seems Spring framework integration has been changed since Stripes 1.5.7.
I now get an error stating that the SpringInterceptor class is missing:
Could not find class [net.sourceforge.stripes.integration.spring.SpringInterceptor] specified by the configuration parameter [Interceptor.Classes]. This value must contain fully qualified class names separated by commas.
This class is requested in web.xml:
<init-param>
<param-name>Interceptor.Classes</param-name>
<param-value>net.sourceforge.stripes.integration.spring.SpringInterceptor</param-value>
</init-param>
Indeed this class is no longer present in package net.sourceforge.stripes.integration.spring.
I suppose my Stripes configuration in web.xml should reflect these changes but I have no clue how to do that.
This form of Spring integration was deprecated in version 1.6.0 of Stripes (https://stripesframework.atlassian.net/browse/STS-633?filter=10230); you have to use the following instead:
<init-param>
<param-name>Extension.Packages</param-name>
<param-value>net.sourceforge.stripes.integration.spring</param-value>
</init-param>

Cannot use JSP property group configuration with jetty-runner 9.1.4

I'm trying to get a new development machine set up. I generally use jetty-runner to run my application .war file (it's a Stripes-based application).
I've got the latest version of jetty-runner (1.9.4), I think. When I try to run my .war file, I get an exception:
java.lang.IllegalStateException: No such servlet: __org.eclipse.jetty.servlet.JspPropertyGroupServlet__
I do in fact have a <jsp-config> block in my web.xml:
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<include-prelude>/WEB-INF/fw/taglibs.jsp</include-prelude>
</jsp-property-group>
</jsp-config>
If I comment that out, then I don't get the exception. I really want that prelude because I don't want to manually include it for every file. Of course, I'm doing that the way I've always done it, where "always" is a pretty long time here.
Is there some new way of doing that stuff for including a JSP prelude, or is there something wrong with my jetty-runner, or what?
edit — I didn't make it clear that I've been using a web.xml like this, with jetty-runner (older versions), for a long time. This is happening to me with the new jetty-runner version only (I haven't tried an old one but I will).
another edit — Version 7.6.15 does not throw that exception (on the same .war file).
(from the mailing list - credit Jan Bartel)
This is a bug we introduced with a change in 9.1.4 to preserve the
order of declaration of servlets and filters. Someone else has raised
a bug for it: https://bugs.eclipse.org/bugs/show_bug.cgi?id=433365
I've committed a fix to head:
https://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/commit/?id=e2ed934978b958d6fccb28a8a5d04768f7c0432d
This fix will be backported to an upcoming 9.1.5 release.

How to deploy a vaadin project on GAE?

I'm trying to deploy an existing vaadin project to GAE.
But I'm constantly getting an error: ClassNotFoundException: com.vaadin.server.GAEApplicationServlet
This is what I've done:
commented out the #WebServlet annotation in my extends UI class
projec properties, checked: use Google App Engine. Thereby some libraries were added to
my WEB-INF/lib folder: gwt-servlet, jsr107, some appendine-*.
created the appengine-web.xml
created the web.xml:
<servlet>
<servlet-name>MyProject</servlet-name>
<servlet-class>com.vaadin.server.GAEApplicationServlet</servlet-class>
<init-param>
<param-name>UI</param-name>
<param-value>de.mypath.ApplicationUI</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>MyProject</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
I can run my project fine if I use com.vaadin.server.VaadinServlet and run on a local tomcat.
But running on a jetty GAE (or also deploying in the cloud) I get the ClassNotFountException mentioned above.
What is wrong here?
It's been a while since I've used GAE, but when I was it seemed like I had to add some jars to WEB-INF/lib myself, despite everything working fine locally. Later I would get warnings about those same jars, but if I removed them I'ld get NoClassDefFoundException again.
Copying vaadin-server-7.5.10.jar to WEB-INF/lib and using com.vaadin.server.GAEVaadinServlet instead of com.vaadin.server.GAEApplicationServlet has resolved the issue.

Error: Wrapper cannot find servlet class VendorRegistration or a class it depends on

I'm a newb whose also been searching for a solution to the same problem. I've followed the steps that the Elite Gentleman and Bozho outlined here. So first of all, thanks a lot guys. But I still seem to have the same problem. Now as per my understanding and implementation, my situation is as follows:
My servlet class VendorRegistration is available in the folder: C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\VendorReg\WEB-INF\classes
My web.xml is present at: C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\VendorReg\WEB-INF\
However, I still seem to be getting the error:
****HTTP Status 500 -
type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: Wrapper cannot find servlet class VendorRegistration or a class it depends on****
I have also appended my web.xml file below for your consideration:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<servlet>
<servlet-name>VendorRegistration</servlet-name>
<servlet-class>VendorRegistration</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>VendorRegistration</servlet-name>
<url-pattern>/VendorRegistration</url-pattern>
</servlet-mapping>
</web-app>
I am trying to access the servlet through the URL: http://localhost:8080/VendorReg/VendorRegistration. What am I missing ? I had compiled the .class file sometime before I installed Apache. And hence directly copied pasted the class file in the folder. Could that be a problem ?
The servlet or one of its dependencies is missing in the classpath.
First of all, always put Java classes in a package, also servlets. Packageless classes are invisible to classes in a normal package. For servlets, this works in specific environments only. You don't want to be dependent on that.
package com.example;
public class VendorRegistration extends HttpServlet {
// ...
}
With this package, the compiled .class file must end up in /WEB-INF/classes/com/example/VendorRegistration.class. Don't forget to alter the associated <servlet-class> entry in web.xml accordingly.
<servlet>
<servlet-name>VendorRegistration</servlet-name>
<servlet-class>com.example.VendorRegistration</servlet-class>
</servlet>
If that doesn't help, then you should put the classes or JAR files containing the (in)direct classes which are specified in any of the servlet's import statements also in /WEB-INF/classes (for .class files) or /WEB-INF/lib (for JAR files). The root cause in the exception stacktrace should tell which class exactly it is. Just read the stacktrace.
See also:
Servlets info page - contains a Hello World and several useful links
From tomcat 6.0 onwards, there is change in <url-pattern>
<servlet>
<servlet-name>VendorRegistration</servlet-name>
<servlet-name>VendorRegistration</servlet-name>
</servlet>
<servlet-mapping>
<servlet-name>VendorRegistration</servlet-name>
<url-pattern>/servlets/servlet/VendorRegistration</url-pattern>
</servlet-mapping>
It worked in my case!
In my case the problem started when I made a copy/paste of HelloWorld.java class example from another project. Finally I solved it out by simply creating a new package, then a new HelloWorld.java from scratch and copy just the code for the doGet() method.
Then I restarted the server and ran http://localhost:8080/mltest/HelloWorld
And it worked!
I faced the same problem too. Actually one of my program which was working already after few changes showed me this error. I even did undo to revert the changes, still It happened to me.
Finally I found a working solution for this for my scenario.
SIMPLE:
1.Just try to clean your project and run again. If it shows the same error and if you are sure there isn't any problem with your code then,
2.Enable the "Build Automatically" menu item under "Project" menu and try to clean your project. This time it worked for me.
Heard this is because when we make some changes and run, eclipse does some changes in its background too. So even if we revert the changes, eclipse might have not reverted the changes which it did in background. So performing these 2 steps will make sure it matches with the user change with its background change.
Hope it helps and solves your problem too.
This is how I solved the problem when I had the same exception with yours.
Ensure you add the right libraries, we need to add the Library Tomcat. At the beginning, I just added the servlet-api.jar, but someone told me it's not a right way. Maybe when you implemented the project in tomcat it had some Conflicts with Tomcat.
Ensure your project in the right folder, %Tomcat_HOME%\webapps\%projectName\WEB-INF\classes\.....
Ensure web.xml in the right folder, and with right form,
%Tomcat_HOME%\webapps\%projectName\WEB-INF\web.xml
Reload the application in Tomcat.
Access the servlet through URL:
http://localhost:port/%projectName%
I'm afraid you made a mistake to try to access a servlet class directly.
Generally, the URL should be your any txt, jsp, html files under your application folder , but the servlet is used for response your "POST" or "Get" request from client side, it's immpossible to access it directly through URL.

The ResourceConfig instance does not contain any root resource classes

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>

Categories