I am creating one REstfulwebservices project. When ever I am going to run this
project then I am getting this error. ClassNot FoundException...ServletAdaptor
problem.
SEVERE: Servlet /XybuyProject threw load() exception
java.lang.ClassNotFoundException:
com.sun.jersey.server.spi.container.servlet.ServletAdaptor
at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:397)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1048)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:996)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4834)
at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5155)
at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5150)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
This is Web.xml :
<?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>FirstProject</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index2.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>ServletAdaptor</servlet-name>
<servlet-class>
com.sun.jersey.server.spi.container.servlet.ServletAdaptor
</servlet-class>
<init-param>
<param-name>com.sun.jersy.config.property.packages</param-name>
<param-value>com.xybuy.webservice</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ServletAdaptor</servlet-name>
<url-pattern>/REST/*</url-pattern>
</servlet-mapping>
</web-app>
can you tel me what is the problem behind it.....
Based on the stacktrace, you seem to be using Tomcat, which is a barebones JSP/Servlet container and not a full fledged Java EE container. Jersey is a JAX-RS implementation which is usually already bundled in fullfledged Java EE application servers such as Glassfish. Perhaps you were reading a Jersey book/tutorial or downloading a sample targeted on Glassfish or another Java EE container and thus it will be assumed that you don't need to install it separately.
However, on Tomcat, Jersey is thus not bundled and you will get ClassNotFoundExceptions on Jersey classes when declaring them in web.xml. You need to download the Jersey JAR file(s) separately and drop them in /WEB-INF/lib folder of the webapp.
Related
I am migrating an application with Java WS from Jboss 5.1.0 to Jboss 6.3.0 EAP. It works fine with Jboss 5.1.0 but I am getting error while deploying the same in Jboss 6.3.0 EAP.
14:42:10,887 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC000001: Failed to start service jboss.deploy
ment.unit."my-app.war".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."dtm-banking.
war".INSTALL: JBAS018733: Failed to process phase INSTALL of deployment "dtm-banking.war"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:166) [jboss-a
s-server-7.4.0.Final-redhat-19.jar:7.4.0.Final-redhat-19]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1980) [jboss-ms
c-1.1.5.Final-redhat-1.jar:1.1.5.Final-redhat-1]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1913) [jboss-msc-1.1.5.F
inal-redhat-1.jar:1.1.5.Final-redhat-1]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_60]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_60]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_60]
Caused by: javax.xml.ws.WebServiceException: java.lang.reflect.UndeclaredThrowableException
at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:371)
at org.jboss.wsf.stack.cxf.deployment.EndpointImpl.doPublish(EndpointImpl.java:66)
at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:251)
at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:539)
at org.jboss.wsf.stack.cxf.configuration.NonSpringBusHolder.configure(NonSpringBusHolder.java:118)
at org.jboss.wsf.stack.cxf.deployment.aspect.BusDeploymentAspect.startDeploymentBus(BusDeploymentAspect.java:137
)
at org.jboss.wsf.stack.cxf.deployment.aspect.BusDeploymentAspect.start(BusDeploymentAspect.java:69)
at org.jboss.as.webservices.deployers.AspectDeploymentProcessor.deploy(AspectDeploymentProcessor.java:74)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:159) [jboss-a
s-server-7.4.0.Final-redhat-19.jar:7.4.0.Final-redhat-19]
... 5 more
Caused by: java.lang.reflect.UndeclaredThrowableException
at com.sun.proxy.$Proxy371.visitLabel(Unknown Source)
at org.apache.cxf.jaxws.WrapperClassGenerator.createWrapperClass(WrapperClassGenerator.java:213)
at org.apache.cxf.jaxws.WrapperClassGenerator.generate(WrapperClassGenerator.java:122)
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.generatedWrapperBeanClass(JaxWsServiceFactoryBean.java:6
83)
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.getExtraClass(JaxWsServiceFactoryBean.java:653)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass(ReflectionServiceFactoryBea
n.java:484)
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.buildServiceFromClass(JaxWsServiceFactoryBean.java:704)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBe
an.java:550)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:265)
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:215)
at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java
:102)
at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:159)
at org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:211)
at org.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:456)
at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:334)
... 13 more
Caused by: java.lang.NoSuchMethodException: org.objectweb.asm.MethodWriter.visitLabel(org.objectweb.asm.Label)
at java.lang.Class.getMethod(Class.java:1665) [rt.jar:1.7.0_60]
at org.apache.cxf.common.util.ReflectionInvokationHandler.invoke(ReflectionInvokationHandler.java:85)
... 28 more
I understand Jboss 6.3.0 EAP uses CXF implementation for webservice, but I am looking for simple Java WS to use the standard Java EE environment.
tried the following in jboss-deployment-structure.xml
<exclude-subsystems>
<subsystem name="webservices" />
</exclude-subsystems>
this got rid of the exception at deployment time but I get a Classcast exception when invoking the wsdl for the service
http://localhost:8080/myapp/myservice?wsdl
JBWEB000235: Allocate exception for servlet MyWebService: java.lang.ClassCastException: com.example.webservice.endpoint.DataService cannot be cast to javax.servlet.Servlet
any idea?
The problem is bundling asm.jar in your deployment.
Try remove it and add this to your jboss-deployment-structure.xml:
<jboss-deployment-structure>
<deployment>
<dependencies>
...
<module name="asm.asm" />
...
</dependencies>
</deployment>
</jboss-deployment-structure>
See more: https://developer.jboss.org/message/823745
The answer that fixed things for me was:
I had the same problem. Adding jboss-deployment-structure.xml only
work for WAR files. If I depolyed the WAR inside an EAR I got the
error back. So I added
<global-modules>
<module name="asm.asm" slot="main"/>
</global-modules>
to the current jboss configuration, ie standalone-full.xml The it
work fine for me.
So if anyone stumbles upon this question, give it a try.
Rifer this page too.
https://access.redhat.com/solutions/690353
The above Error is thrown when for given class particular method not
found. Hence user is packaging asm jar in their application and class
"org.objectweb.asm.MethodWriter" which contains in a jar does not have
method "public void visitLabel(org.objectweb.asm.Label);" hence
getting "java.lang.NoSuchMethodException".
Hi Friends
I have created a sample web service using netbeans 7.3. It works fine on localhost when running through tomcat linked with netbeans.
When I deploy it in webapps folder of the tomcat 7 on any standalone machine, it works fine too. BUT when we transfer the code from webapps to public_html folder of online linux server, I get 404 error. please see the file. Online server has tomcat 7 which is linked through with Apache
web.xml
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web- app_2_5.xsd">
<listener>
<listener-class>
com.sun.xml.ws.transport.http.servlet.WSServletContextListener
</listener-class>
</listener>
<servlet>
<servlet-name>EduCloudWS</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>EduCloudWS</servlet-name>
<url-pattern>/EduCloudWS</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
sun-jaxws.xml
<endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0">
<endpoint implementation="com.educloud.ws.EduCloudWS" name="EduCloudWS" url-pattern="/EduCloudWS"/>
</endpoints>
I am trying to access by following links, both don't work and give a 404 error
http://domainname.com/EduCloudWS
http://domainname.xom/EduCloudWS/EduCloudWS
Thanks for the help
I'm trying to exclude the webservices subsystem in my jboss AS 7.1.1 by adding a jboss-deployment-structure.xml file, which looks as follows:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<exclude-subsystems>
<subsystem name="webservices" />
</exclude-subsystems>
</deployment>
</jboss-deployment-structure>
In Eclipse, I get an error in the aforementioned file which marks "deployment" as an invalid element. If I disregard the error and run my project, I get the following error:
19:40:15,531 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC00001: Failed to start service jboss.deployment.unit."CXF.war".STRUCTURE: org.jboss.msc.service.StartException in service jboss.deployment.unit."CXF.war".STRUCTURE: Failed to process phase STRUCTURE of deployment "CXF.war"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:119) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) [rt.jar:1.6.0_45]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) [rt.jar:1.6.0_45]
at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_45]
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: Error loading jboss-structure.xml from C:\jboss-as-7.1.1.Final\jboss-as-7.1.1.Final\standalone\deployments\CXF.war\WEB-INF\jboss-deployment-structure.xml
at org.jboss.as.server.deployment.module.descriptor.DeploymentStructureDescriptorParser.parse(DeploymentStructureDescriptorParser.java:277) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.server.deployment.module.descriptor.DeploymentStructureDescriptorParser.parse(DeploymentStructureDescriptorParser.java:249) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.server.deployment.module.descriptor.DeploymentStructureDescriptorParser.deploy(DeploymentStructureDescriptorParser.java:134) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
... 5 more
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[2,1]
Message: Unexpected element '{urn:jboss:deployment-structure:1.2}jboss-deployment-structure'
at org.jboss.staxmapper.XMLMapperImpl.processNested(XMLMapperImpl.java:108)
at org.jboss.staxmapper.XMLMapperImpl.parseDocument(XMLMapperImpl.java:69)
at org.jboss.as.server.deployment.module.descriptor.DeploymentStructureDescriptorParser.parse(DeploymentStructureDescriptorParser.java:271) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
... 8 more
Based on the answer from this URL:
How can I use Apache CXF 2.6.7 as dependency of my war project and not CXF that is installed in the modules of JBoss 7.1?
Just a note, exclude-subsystems functionality and
deployment-strucure:1.2 was added in 7.1.2 and as such will not work
on on 7.1.1.
I'm using JBoss AS 7.1.1, so this explains it.
From the following error i can see that the structure of war file deployed is incorrect, so you can change it to a correct format and then try...
19:40:15,531 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC00001: Failed to start service jboss.deployment.unit."CXF.war".STRUCTURE:
From the following error - urn:jboss:deployment-structure:1.2 named subsystem is not present(i think it may be - urn:jboss:domain:deployment-scanner:1.1) and it is also showing the "parser error" so check the xml file also :
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[2,1]
Message: Unexpected element '{urn:jboss:deployment-structure:1.2}jboss-deployment-structure'
A simple war file structure for reference as follows :
Demo.war
|
|---- META-INF
| |----jboss-deployment-structure.xml
| |----MANIFEST.MF
|
|---- WEB-INF
| |---- classes
| |
| |---- lib
| |
| |---- web.xml
|
|---- index.jsp
<web-app version="3.0" 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_3_0.xsd"
metadata-complete="false">
If you want to migrate from weblogic to JBoss, just change the schema as above.
It will works.
I am using the following setup to deploy a REST webservice on Tomcat 6 and it works:
<web-app>
<servlet>
<servlet-name>RestServlet</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>RestServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
With the above setup, Tomcat scans WEB-INF/classes and WEB-INF/lib folders for the resources.
I then changed it to the following setup to use Application sub-class:
<web-app>
<servlet>
<servlet-name>RestServlet</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>test.MyApplication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>RestServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
where test.MyApplication is the sub-class of Application returning the resource class:
public class MyApplication extends Application {
public Set<Class<?>> getClasses() {
Set<Class<?>> s = new HashSet<Class<?>>();
s.add(MyResource.class);
return s;
}
}
But still the server scans WEB-INF/classes and WEB-INF/lib for the resources.
What am I missing? Does the server still scan WEB-INF when Application subclass is set in the web.xml?
Does the server still scan WEB-INF when Application subclass is set in the web.xml?
No it doesn't. The documentation explains that scanning the path is done if no resource configuration related initialization parameters (like javax.ws.rs.Application) are present.
You should see what's in your server logs. When Jersey initializes it logs what it's doing and for a classpath scan it prints something like:
INFO: Scanning for root resource and provider classes in the Web app resource paths:
/WEB-INF/lib
/WEB-INF/classes
When you provide an Application class it prints this instead:
INFO: Instantiated the Application class test.MyApplication
You should make sure that the proper web.xml file is deployed when the server starts. Maybe you still have the old version deployed.
I am having problems deploying my web application, and it has been puzzling me for 3 weeks after continually blaming our hosting company and their server.
First of all, the web application was deploying fine using manager on tomcat 5.
Then I asked to change to tomcat 6, which they did, and now the application does not deploy and gives the now all so familiar SEVERE: Error deploying configuration descriptor XXXX.xml.
BUT in Eclipse I build and run my application on Tomcat 6 which works fine!, but when again when I try and deploy the packaged war on my local server via manager, I get the SEVERE error.
There is something wrong with my deployment descriptor which is sensitive to tomcat but not in eclipse. I read somewhere about case sensitive and I have double checked this.
I have then tried and commented out the context - still does not work, and everything in web.xml apart from the welcome-file-list. Still I get the same error.
I am out of ideas and very confused.
Below I have posted web.xml and context.xml (for confidentiality reasons I have to XXXX out the names).
<?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>XXXX</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>restSdkService</servlet-name>
<servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.XXXX.core.TestWebApp</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>restSdkService</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<resource-ref>
<description>MySQL Datasource example</description>
<res-ref-name>jdbc/XXXX</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource name="jdbc/emotifi" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="XXXX" password="XXXX"
driverClassName="com.mysql.jdbc.Driver"
url="XXXX"/>
<Resource name="jdbc/emotifi_web" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="XXXX" password="XXXX"
driverClassName="com.mysql.jdbc.Driver"
url="XXXX"/>
</Context>