So, I'm trying to deploy a simple Web Service webapp into ServiceMix.
SMX version: 5.4.0,
Java version: 1.7.0_75
The code is located at: https://github.com/yngwietiger/HelloWebService.git
My app contains 2 servlets: HelloWebService (exposes a simple web service) and MyServlet (very basic servlet)
I do a mvn clean install to build the war/bundle.
If I run mvn tomcat:run, it works fine, I can hit both servlets.
e.g. http://localhost:8080/HelloWebService/myservlet
and
http://localhost:8080/HelloWebService/helloWebService?wsdl
But when I deploy into SMX, I get the following error:
2015-04-27 10:14:11,155 | ERROR | pool-7-thread-1 | WebAppPublisher | ? ? | 201 - org.ops4j.pax.web.pax-web-extender-war - 3.1.2 | Error deploying web application
com.sun.xml.ws.transport.http.servlet.WSServletException: WSSERVLET11: failed to parse runtime descriptor: java.lang.LinkageError: loader constraint violation: when resolving field "DATETIME" the class loader (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) of the referring class, javax/xml/datatype/DatatypeConstants, and the class loader (instance of <bootloader>) for the field's resolved type, pe/DatatypeConstants, have different Class objects for that type
at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.parseAdaptersAndCreateDelegate(WSServletContextListener.java:141)[269:HelloWebService:0.0.0]
at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.contextInitialized(WSServletContextListener.java:152)[269:HelloWebService:0.0.0]
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:782)[64:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:424)[64:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:774)[64:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:249)[64:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:717)[64:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doStart(HttpServiceContext.java:222)[73:org.ops4j.pax.web.pax-web-jetty:3.1.2]
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)[64:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
at org.ops4j.pax.web.service.jetty.internal.JettyServerImpl$1.start(JettyServerImpl.java:202)[73:org.ops4j.pax.web.pax-web-jetty:3.1.2]
at org.ops4j.pax.web.service.internal.HttpServiceStarted.end(HttpServiceStarted.java:1032)[72:org.ops4j.pax.web.pax-web-runtime:3.1.2]
at org.ops4j.pax.web.service.internal.HttpServiceProxy.end(HttpServiceProxy.java:422)[72:org.ops4j.pax.web.pax-web-runtime:3.1.2]
at org.ops4j.pax.web.extender.war.internal.RegisterWebAppVisitorWC.end(RegisterWebAppVisitorWC.java:341)[201:org.ops4j.pax.web.pax-web-extender-war:3.1.2]
at org.ops4j.pax.web.extender.war.internal.model.WebApp.accept(WebApp.java:678)[201:org.ops4j.pax.web.pax-web-extender-war:3.1.2]
at org.ops4j.pax.web.extender.war.internal.WebAppPublisher$WebAppDependencyListener.register(WebAppPublisher.java:237)[201:org.ops4j.pax.web.pax-web-extender-war:3.1.2]
at org.ops4j.pax.web.extender.war.internal.WebAppPublisher$WebAppDependencyListener.addingService(WebAppPublisher.java:182)[201:org.ops4j.pax.web.pax-web-extender-war:3.1.2]
at org.ops4j.pax.web.extender.war.internal.WebAppPublisher$WebAppDependencyListener.addingService(WebAppPublisher.java:135)[201:org.ops4j.pax.web.pax-web-extender-war:3.1.2]
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:932)[karaf.jar:2.4.1]
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:1)[karaf.jar:2.4.1]
at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)[karaf.jar:2.4.1]
at org.osgi.util.tracker.AbstractTracked.trackInitial(AbstractTracked.java:183)[karaf.jar:2.4.1]
at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:317)[karaf.jar:2.4.1]
at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:261)[karaf.jar:2.4.1]
at org.ops4j.pax.web.extender.war.internal.WebAppPublisher.publish(WebAppPublisher.java:101)[201:org.ops4j.pax.web.pax-web-extender-war:3.1.2]
at org.ops4j.pax.web.extender.war.internal.WebObserver.deploy(WebObserver.java:213)[201:org.ops4j.pax.web.pax-web-extender-war:3.1.2]
at org.ops4j.pax.web.extender.war.internal.WebObserver$1.doStart(WebObserver.java:175)[201:org.ops4j.pax.web.pax-web-extender-war:3.1.2]
at org.ops4j.pax.web.extender.war.internal.extender.SimpleExtension.start(SimpleExtension.java:58)[201:org.ops4j.pax.web.pax-web-extender-war:3.1.2]
at org.ops4j.pax.web.extender.war.internal.extender.AbstractExtender$1.run(AbstractExtender.java:266)[201:org.ops4j.pax.web.pax-web-extender-war:3.1.2]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)[:1.7.0_75]
at java.util.concurrent.FutureTask.run(FutureTask.java:262)[:1.7.0_75]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)[:1.7.0_75]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)[:1.7.0_75]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)[:1.7.0_75]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)[:1.7.0_75]
at java.lang.Thread.run(Thread.java:745)[:1.7.0_75]
Caused by: java.lang.LinkageError: loader constraint violation: when resolving field "DATETIME" the class loader (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) of the referring class, javax/xml/datatype/DatatypeConstants, and the class loader (instance of <bootloader>) for the field's resolved type, pe/DatatypeConstants, have different Class objects for that type
at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl.<clinit>(RuntimeBuiltinLeafInfoImpl.java:267)
at com.sun.xml.bind.v2.model.impl.RuntimeTypeInfoSetImpl.<init>(RuntimeTypeInfoSetImpl.java:65)
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.createTypeInfoSet(RuntimeModelBuilder.java:133)
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.createTypeInfoSet(RuntimeModelBuilder.java:85)
at com.sun.xml.bind.v2.model.impl.ModelBuilder.<init>(ModelBuilder.java:156)
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.<init>(RuntimeModelBuilder.java:93)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:450)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:298)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:141)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1157)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:188)
at com.sun.xml.bind.api.JAXBRIContext.newInstance(JAXBRIContext.java:111)
at com.sun.xml.ws.developer.JAXBContextFactory$1.createJAXBContext(JAXBContextFactory.java:113)
at com.sun.xml.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:166)
at com.sun.xml.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:159)
at java.security.AccessController.doPrivileged(Native Method)[:1.7.0_75]
at com.sun.xml.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:158)
at com.sun.xml.ws.model.AbstractSEIModelImpl.postProcess(AbstractSEIModelImpl.java:99)
at com.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:250)
at com.sun.xml.ws.server.EndpointFactory.createSEIModel(EndpointFactory.java:343)
at com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:205)
at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:513)
at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parseAdapters(DeploymentDescriptorParser.java:257)
at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parse(DeploymentDescriptorParser.java:151)
at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.parseAdaptersAndCreateDelegate(WSServletContextListener.java:131)
... 34 more
My web.xml is as follows:
<?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>jaxwsExample</display-name>
<listener>
<listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>
<servlet>
<servlet-name>helloWebService</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>helloWebService</servlet-name>
<url-pattern>/helloWebService</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>myservlet</servlet-name>
<servlet-class>com.webservices.demo.MyServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>myservlet</servlet-name>
<url-pattern>/myservlet</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>120</session-timeout>
</session-config>
</web-app>
And here is my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>HelloWebService</groupId>
<artifactId>HelloWebService</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>JAX-WS webservice with maven</name>
<dependencies>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2.5</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>HelloWebService</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<version>2.5.3</version>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
<Embed-Directory>WEB-INF/lib</Embed-Directory>
<Embed-Transitive>true</Embed-Transitive>
<Import-Package>*;resolution:=optional</Import-Package>
<Web-ContextPath>/HelloWebService</Web-ContextPath>
<Webapp-Context>/HelloWebService</Webapp-Context>
<_wab>src/main/webapp</_wab>
</instructions>
<supportedProjectTypes>
<supportedProjectType>war</supportedProjectType>
</supportedProjectTypes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
All of the code is at the GITHUB link at the top, if anyone wants to try it.
If I comment out the WS servlet and listener, I can deploy in SMX and hit the simple servlet (MyServlet). But I just can't get the WS servlet to work.
Any thoughts/ideas?
I thought this would be easy, but it's a real pain.
I suspect it's something with my maven-bundle-plugin configuration, but I really don't know.
Any help would be greatly appreciated.
Thanks.
The plain jax ws from sun does not work very well in OSGi. You should try with Apache CXF.
See:
Karaf Tutorial Part 4 - CXF Services in OSGi
Related
I am trying to play around with Eclipse/Java and I am making a Dynamic Web Project in Eclipse. I have followed tutorials online and looked at several other Stackoverflow posts, but i'm still having the same problem.
When I run my server and try to hit my endpoint /test, I get a 404 error. Here is my code:
My Java Class:
package TestPackage;
import javax.ws.rs.Path;
import javax.ws.rs.GET;
#Path("/test")
public class Test {
#GET
public String Hello() {
return "hello";
}
}
My Pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>RestDemo</groupId>
<artifactId>RestDemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.25</version>
</dependency>
</dependencies>
</project>
I read that if you're using Jersey 2.+, you wouldn't have to fiddle around with your web.xml, so it's the standard format:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<display-name>RestDemo</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>
</web-app>
So when I try to call http://localhost:8080/RestDemo/test, I get a 404 error. Any idea what's going on?
In Servlet 2.5 environment, you have to explicitly declare the Jersey container Servlet in your Web application's web.xml deployment descriptor file.
As per https://jersey.java.net/documentation/latest/user-guide.html#deployment.servlet
Example 4.10. Hooking up Jersey as a Servlet
<web-app>
<servlet>
<servlet-name>MyApplication</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
...
</init-param>
</servlet>
...
<servlet-mapping>
<servlet-name>MyApplication</servlet-name>
<url-pattern>/myApp/*</url-pattern>
</servlet-mapping>
...
</web-app>
I was able to run the same Struts 2 application in previous version of Eclipse.
But when I tried to run it in Mars.1, it is giving the below exception:
Nov 25, 2015 1:16:56 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/GoogleChart] threw exception [javax.servlet.ServletException: java.lang.NoClassDefFoundError: org/codehaus/jackson/map/ObjectMapper] with root cause
java.lang.ClassNotFoundException: org.codehaus.jackson.map.ObjectMapper
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1854)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1703)
My POM looks like this :
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>AutoPlat</groupId>
<artifactId>AutoPlat</artifactId>
<version>0.0.5</version>
<name>AutoPlat</name>
<description>AutoPlat</description>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.3.16</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
</dependencies>
<dependencyManagement>
</dependencyManagement>
<packaging>war</packaging>
</project>
And, web.xml :
<?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_3_0.xsd"
version="3.0" metadata-complete="true">
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<!-- <servlet>
<servlet-name>PieChartServlet</servlet-name>
<servlet-class>chart.PieChartServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>PieChartServlet</servlet-name>
<url-pattern>/PieChartServlet</url-pattern>
</servlet-mapping> -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>DashBoard.jsp</welcome-file>
</welcome-file-list>
</web-app>
What is the cause of this error ?
Caused by:
java.lang.ClassNotFoundException: org.codehaus.jackson.map.ObjectMapper
Jackson is missing in the classpath
I guess that the underline problem is that:
Maven
Now that Codehaus no longer serves up Maven repositories, you will
need to change your configuration.
If your configuration is not updated and you slam our redirector, then
you may be served invalid JAR files with status 200 to encourage you
to update your configuration.
Making Maven Work
settings.xml
In ~/.m2/settings.xml you can update the URL to be used for specific
repositories.
For example:
<repositories>
<repository>
<id>codehaus-mule-repo</id>
<name>codehaus-mule-repo</name>
<url>
https://repository-master.mulesoft.org/nexus/content/groups/public/
</url>
<layout>default</layout>
</repository>
</repositories>
Also note that that artifact has been migrated and evoluted a lot since 1.9.13, now it has reached 2.6.3:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.6.3</version>
</dependency>
I have a webapp which is Maven-enabled. When I run the build with mvn install everything looks good, classes are under WEB-INF/classes, maven dependencies are under WEB-INF/lib and web.xml file is under WEB-INF/ as they should.
However, when I deploy from within Eclipse using Tomcat 7.x, it can't find the listener class. The com.test.backend.BackendApplication servlet is not invoked either, even though it is configured in the web.xml to load on startup.
I noticed that the classes are not showing up under Eclipse's "Deployed Resources" node on the Project Explorer, but I have no idea how to make it show up there.
Here is the exception I get:
SEVERE: Error configuring application listener of class com.test.backend.BackendServletContextListener
java.lang.ClassNotFoundException: com.test.backend.BackendServletContextListener
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:532)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:514)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:142)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4876)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5455)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
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 my 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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>com.test.backend</display-name>
<servlet>
<servlet-name>jersey-servlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.test.backend.BackendApplication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<listener>
<listener-class>com.test.backend.BackendServletContextListener</listener-class>
</listener>
</web-app>
My pom.xml looks like this:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>backend</artifactId>
<packaging>war</packaging>
<version>1.0.0.0</version>
<properties>
<java.version>1.8</java.version>
<maven.version>3.1.0</maven.version>
<jersey.version>2.14</jersey.version>
<jersey.test.version>2.15</jersey.test.version>
<jackson.version>2.5.2</jackson.version>
<guice.version>4.0</guice.version>
</properties>
<dependencies>
...
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>prepare-war</id>
<phase>prepare-package</phase>
<configuration>
<archiveClasses>true</archiveClasses>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix />
</manifest>
<manifestEntries>
<Implementation-Build>${build.number}</Implementation-Build>
<Implementation-Title>${project.name}</Implementation-Title>
<Implementation-Vendor>RestApi.com</Implementation-Vendor>
<Built-By>${user.name}</Built-By>
<Built-OS>${os.name}</Built-OS>
<Build-Date>${build.date}</Build-Date>
</manifestEntries>
</archive>
<webResources>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>./target/${project.artifactId}</directory>
</resource>
</webResources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
An help is greatly appreciated! I searched for hours but so far no luck...
Right click on the maven Web project then under deployment assembly add "folder with the listener classes in target folder".
For example if ServletContextListener implementation is present in the package com.company.listeners, deployment assembly should have the following folder mapping:
target/<applicationname>/WEB-INF/classes/com/company/listeners
Should be mapped to
WEB-INF/classes/com/company/listeners
I think this is related to class loader hierarchy in tomcat and the class loader used for loading listeners (and classes available for that class loader).
I just ran into this problem myself. After a lot of cursing I realised I didn't have build automatically box checked. (Knew I should never have turned the damn thing off!)
Solved it for me. Hopefully this post will save someone else's sanity!
I am trying to deploy my first rest application using jersey 2.17.
I am using Maven, GlassFish 3.1.2.2 for deployment.
Application runs in eclipse (tomcat), but gives following error when deploying through glassfish admin console.
Error occurred during deployment: Exception while loading the app :
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException:
java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;.
Please see server.log for more details.
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>JerseyExample</groupId>
<artifactId>JerseyExample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.17</version>
</dependency>
</dependencies>
</project>
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"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>JerseyExample</display-name>
<servlet>
<servlet-name>MyJerseyExample</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>jerseyExample.resource</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MyJerseyExample</servlet-name>
<url-pattern>/example/*</url-pattern>
</servlet-mapping>
</web-app>
Ok looked at your issue. The External Glassfish v 3.1.2.2 that you are using is JAVA-EE 6 compatible. And the one through which you are running your app in eclipse is JAVA-EE 7 compatible.
Have a look at both the java docs:
Application class Java Doc for EE6
Application class Java Doc for EE7
You will see that the getProperties method got introduced in JAVA-EE 7.
Simply upgrade to glassfish version-4.x that is compatible with JAVA-EE 7. Assuming nothing else breaks should be good.
I'm trying to run a maven project with jsf on the app engine development server and for every managed bean I get an 404 error (Not found). I edited the files from http://www.mkyong.com/jsf2/jsf-2-0-hello-world-example/ to work with GAE. Below are the modified files:
HelloBean.java
package com.mkyong.common;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import java.io.Serializable;
#ManagedBean
#RequestScoped
public class HelloBean implements Serializable {
public String getName() {
return "abc";
}
}
web.xml
<?xml version="1.0" encoding="utf-8"?>
<web-app
version="2.5"
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">
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.enableThreading</param-name>
<param-value>false</param-value>
</context-param>
<!-- Faces Servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Faces Servlet Mapping -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<!-- Welcome page -->
<welcome-file-list>
<welcome-file>index.jsf</welcome-file>
</welcome-file-list>
</web-app>
index.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>JSF 2.0 Hello World</title>
</h:head>
<h:body bgcolor="white">
<h3>JSF 2.0 Hello World Example - welcome.xhtml</h3>
<h4>Welcome #{helloBean.name}</h4>
</h:body>
</html>
and pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mkyong.common</groupId>
<artifactId>JavaServerFaces</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>JavaServerFaces Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<!-- Google AppEngine -->
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>1.8.5</version>
</dependency>
<!-- Servlet dependency -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<!-- JSF -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.4</version>
</dependency>
</dependencies>
<build>
<finalName>JavaServerFaces</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<archiveClasses>true</archiveClasses>
<webResources>
<resource>
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
<filtering>true</filtering>
<targetPath>WEB-INF</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>1.8.5</version>
<configuration>
<disableUpdateCheck>true</disableUpdateCheck>
</configuration>
</plugin>
</plugins>
</build>
</project>
The other files: appengine-web.xml and logging.properties are not changed.
What is wrong? JSF dependencies/configuration?
You're using JSF 2.2.4 but you claim to use JSF 2.0, noted by your hello world example where you just copied/pasted from a tutorial the title JSF 2.0 Hello World. Note that JSF 2.2 needs at least Servlet 3.0 API to work but you use Servlet 2.5 API (noted in your maven pom). You have two ways to solve this:
Downgrade JSF to 2.0. I won't recommend doing this, but will solve the problem.
Upgrade your servlet API to 3.0. Note that this depends on the servlet version supported by GAE.