Error instantiating servlet class org.glassfish.jersey.servlet.ServletContainer - rest

Hi Trying to write a simple rest webservice. And following the tutorial below:
http://www.tutorialspoint.com/restful/index.htm
But i am getting
HTTP Status 500 - Error instantiating servlet class org.glassfish.jersey.servlet.ServletContainer
Exception:
<body>
<h1>HTTP Status 500 - Error instantiating servlet class org.glassfish.jersey.servlet.ServletContainer</h1>
<div class="line"></div>
<p>
<b>type</b> Exception report
</p>
<p>
<b>message</b>
<u>Error instantiating servlet class org.glassfish.jersey.servlet.ServletContainer</u>
</p>
<p>
<b>description</b>
<u>The server encountered an internal error that prevented it from fulfilling this request.</u>
</p>
<p>
<b>exception</b>
</p>
<pre>javax.servlet.ServletException: Error instantiating servlet class org.glassfish.jersey.servlet.ServletContainer
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:745)
</pre>
<p>
<b>root cause</b>
</p>
<pre>java.lang.ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1308)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1142)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
Following is the code (Which is mostly same as the tutorial)
package com.abhi;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
#Path("/UserService")
public class UserService {
UserDao userDao = new UserDao();
#GET
#Path("/users")
#Produces(MediaType.APPLICATION_XML)
public List<User> getUsers(){
return userDao.getAllUsers();
}
}
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>MyRestPrjct</display-name>
<servlet>
<servlet-name>Jersey RESTful Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.abhi</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Jersey RESTful Application</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<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>

I was just not placing the jars in proper way. Instead of placing the required jar in webapps\MyRestPrjct\WEB-INF\lib, I was placing it in webapps\MyRestPrjct\WEB-INF\lib\libs.
It is working fine after I the moved the jars from libs to lib.

Placing all the jars in WEB-INF/lib folder resolved the issue for me.

i too faced similar issue when i did the same tutorial, the problem i found out was the servelt class specified in the web.xml is
org.glassfish.jersey.servlet.ServletContainer
but when i checked in the jars there is no package in the libraries with the above path so i change it to the existing one
com.sun.jersey.spi.container.servlet.ServletContainer
and it solved the issue.

I too got the same exception when trying to run the same module from tutorialspoint. All I did is to download the below jars and added to project. It worked fine.
jersey-common-2.0-m03.jar
jersey-server-2.0-m03.jar
jersey-container-servlet-core-2.28.jar

In my case worked by adding maven dependencies in deployment assembly.(For Maven Project*)
Right click project name (in eclipse) > configure build path > Deployment Assembly (in Left bar) > Add > java build Path Entries > Maven Dependencies > Finish

Related

HTTP 404 error. The requested resource is not available. I am using Jdk 1.8 and eclipse jee mars [duplicate]

This question already has answers here:
Servlet returns "HTTP Status 404 The requested resource (/servlet) is not available"
(19 answers)
Closed 5 years ago.
I am putting my code where I am facing problem.
WriteToPdf1.java
import java.io.*;
import javax.servlet.http.*;
import com.darwinsys.spdf.PDF;
import com.darwinsys.spdf.Page;
import com.darwinsys.spdf.Text;
import com.darwinsys.spdf.MoveTo;
public class ServletPDF1 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
PrintWriter out = response.getWriter();
response.setContentType("application/pdf");
response.setHeader("Content-disposition","inline; filename='CreatePDFFile.pdf'");
PDF p = new PDF(out);
Page p1 = new Page(p);
p1.add(new MoveTo(p, 200, 700));
p1.add(new Text(p, "Hi This is created PDF file by using Servlet"));
p1.add(new Text(p, "by us...Bhumesh Patel...."));
p.add(p1);
p.setAuthor("Bhumesh Patel....");
p.writePDF();
}
}
index.html
CLICK HERE
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>WriteToPdf1</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>ServletPdf1</servlet-name>
<servlet-class>ServletPdf1</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletPdf1</servlet-name>
<url-pattern>/servlet1</url-pattern>
</servlet-mapping>
</web-app>
Please help I am doing this in eclipse jee mars and tried several options but could not execute it.I have attached all code. plz help.
If you changed the url mapping of a servlet in your web.xml file during runtime of the server, (depending on your server) it will not pick up on the changes. Try cleaning, rebuilding and restarting the server.

Jersey app deployment error

I have a simple jersey based REST Web service where i'm trying to do a test GET run..
Using Jersey 2.7 & Servlet 3.0 container, I have tried configuring the application using the jersey doc ( JAX-RS application without an Application subclass
I have defined a resource
#Path("/bolt")
public class SpringRequestResource extends BaseResource {
#GET
#Produces("text/plain")
public String getHello() {
return "Hello World!";
}
And my deployment descriptor web.xml as
<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">
<display-name>Alpha</display-name>
<servlet>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
</servlet>
<servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/myService/*</url-pattern>
</servlet-mapping>
</web-app>
However, upon throwing a GET request via browser through a url http://myName.xyz.com:6080/[projectName]/myService/bolt
It throws the following exception -
javax.servlet.ServletException: Servlet.init() for servlet javax.ws.rs.core.Application threw exception
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:851)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:278)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:745)
root cause
java.lang.IllegalStateException: The resource configuration is not modifiable in this context.
org.glassfish.jersey.server.ResourceConfig$ImmutableState.register(ResourceConfig.java:270)
org.glassfish.jersey.server.ResourceConfig$ImmutableState.register(ResourceConfig.java:218)
org.glassfish.jersey.server.ResourceConfig.register(ResourceConfig.java:448)
org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:309)
org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:168)
org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:358)
javax.servlet.GenericServlet.init(GenericServlet.java:160)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:851)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:278)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:745)
Can't seem to figure out the problem here.
I cannot reproduce the issue with Jersey 2.9. You can try to migrate to Jersey 2.9. If it does not help you can create an new issue in https://java.net/jira/browse/JERSEY as this is probably a bug and not your fault. It would be good if you could attach a simple reproducible test case (simple executable maven project that reproduces the problem).
The workaround would be to use extension of Application class or ResourceConfig to configure the application.

exception java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer

I just made my first REST api based on this http://www.vogella.com/articles/REST/article.html
I am using eclipse kepler, tomcat7, and Jersey
when I try to "Run on server" I get this error:
SEVERE: Servlet /de.vogella.jersey.first threw load() exception
java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:527)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:509)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:137)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5176)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5460)
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)
Here is the source code:
package de.vogella.jersey.first;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
#Path("/hello")
public class Hello {
// This method is called if TEXT_PLAIN is request
#GET
#Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello() {
return "Hello Jersey";
}
// This method is called if XML is request
#GET
#Produces(MediaType.TEXT_XML)
public String sayXMLHello() {
return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey" + "</hello>";
}
// This method is called if HTML is request
#GET
#Produces(MediaType.TEXT_HTML)
public String sayHtmlHello() {
return "<html> " + "<title>" + "Hello Jersey" + "</title>"
+ "<body><h1>" + "Hello Jersey" + "</body></h1>" + "</html> ";
}
}
here is the 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>de.vogella.jersey.first</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>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
here are the libraries that I have added from Jersey:
asm-all-repackaged-2.2.0-b14.jar
cglib-2.2.0-b14.jar
guava-14.0.1.jar
hk2-api-2.2.0-b14.jar
hk2-locator-2.2.0-b14.jar
hk2-utils-2.2.0-b14.jar
javax.annotation-api-1.2.jar
javax.inject-2.2.0-b14.jar
javax.servlet-api-3.0.1.jar
javax.ws.rs-api-2.0.jar
jaxb-api-2.2.7.jar
jersey-client.jar
jersey-common.jar
jersey-container-servlet-core.jar
jersey-container-servlet.jar
jersey-server.jar
org.osgi.core-4.2.0.jar
osgi-resource-locator-1.0.1.jar
persistence-api-1.0.jar
validation-api-1.1.0.Final.jar
If you are using jersey 2.x API, you need to rename the classes as done below, and your issue will be resolved.
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>org.glassfish.jersey.config.property.packages</param-name>
<param-value>com.practise.rest</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
Karthik [aka DjNickZ]
You are getting
com.sun.jersey.spi.container.servlet.ServletContainer
That means you are using different version of jar. You added jersey-server.jar this jar is upgrade to jersey-servlet-1.17.jar.
So add jersey-servlet-1.17.jar to your project.
We get this error because of build path issue. You should add "Server Runtime" libraries in Build Path.
"java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer"
Please follow below steps to resolve class not found exception.
Right click on project --> Build Path --> Java Build Path --> Add Library --> Server Runtime --> Apache Tomcat v7.0
Thanks,
Sachin G N
You need to add the following jar files to your web-inf/lib folder, also you need to configure build path -- Right click your project--Build path -- configure build path -- libraries -- add external jars (add all the below jar files). And restart server

Jersey REST Web Service, Tomcat, Eclipse and 404's

I've read through a number of posts, but just can't seem to solve my problem. You'll also see tons of posts very similar to this one, even the same tutorial. Even following them, I can't seem to get to the answer.
Essentially, I'm trying to follow the simple tutorial at: http://www.vogella.com/articles/REST/
I've made a few changes to make it compatible with Jersey 2.x
I'm using:
Eclipse
Tomcat 6 (Deployed/Run as within Eclipse)
jaxrs-ri-2.0
I've enabled the JAX-RS Facet in Eclipse
Everything builds fine
Tomcat starts fine within Eclipse
I can get to a static page content via:
http://localhost:8080/RestTEST2/index.html
However, when I try to access my service via:
http://localhost:8080/RestTEST2/jaxrs/hello
I receive a 404 with "message not found" and "The requested resource (Not Found) is not available."
Here is my web.xml which is located at /WebContent/WEB-INF/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_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>TestREST2</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<description>JAX-RS Tools Generated - Do not modify</description>
<servlet-name>JAX-RS Servlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>TestREST</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JAX-RS Servlet</servlet-name>
<url-pattern>/jaxrs/*</url-pattern>
</servlet-mapping>
</web-app>
Here is my Java class:
package TestREST;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
// Plain old Java Object it does not extend as class or implements
// an interface
// The class registers its methods for the HTTP GET request using the #GET annotation.
// Using the #Produces annotation, it defines that it can deliver several MIME types,
// text, XML and HTML.
// The browser requests per default the HTML MIME type.
//Sets the path to base URL + /hello
#Path("/hello")
public class Hello {
// This method is called if TEXT_PLAIN is request
#GET
#Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello() {
return "Hello Jersey";
}
// This method is called if XML is request
#GET
#Produces(MediaType.TEXT_XML)
public String sayXMLHello() {
return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey" + "</hello>";
}
// This method is called if HTML is request
#GET
#Produces(MediaType.TEXT_HTML)
public String sayHtmlHello() {
return "<html> " + "<title>" + "Hello Jersey" + "</title>"
+ "<body><h1>" + "Hello Jersey" + "</body></h1>" + "</html> ";
}
}
I also have a JAX-RS User Library configured and referenced that includes all the JAX-RS jars.
Thoughts on what would cause the web service to not be found?
Jersey 2.0 does not recognize init-param with name com.sun.jersey.config.property.packages (web.xml). Try to change it to jersey.config.server.provider.packages as described in ServerProperties.PROVIDER_PACKAGES.
UPDATE (2020): try this link for current apidocs ServerProperties.PROVIDER_PACKAGES:
Thanks a lot.. i've been fighting for it as well.
This combination worked for me:
Tomcat 7.0.55
Eclipse Luna
Java 1.6
Jersey 1.7
web.xml:
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.trgr.cobalt.cmdb.jersey.resource;com.trgr.cobalt.cmdb.jersey.beans;com.trgr.cobalt.cmdb.elasticity</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
I would like to add one answer in this post.I was struggling with same problem for two days and couldn't find the solution.
I tried all the possible solutions provided here but later on I realized that server was giving error of
org.glassfish.jersey.servlet.ServletContainer ClassNotFoundException
This link answers gives the solution if somebody is stuck like me..
org.glassfish.jersey.servlet.ServletContainer ClassNotFoundException
Actually first answer given in this post suggest the solution which is for jersey 2.x bundle and if you are using jersey 1.x then it will keep on giving error.
Kindly refer to link given in answer for further reference
Simply by modifying the configuration of Apache Tomcat v7.0 while creating Dynamic Web Project, to include REST, I solved my problem. It is not enabled by default.
Recently I found myself stuck in this problem. I have got it resolved by following these two points as the solution:
By making the src/main/java as the source directory, and keeping the Project Structure as shown below:
Changing com.sun.jersey.config.property.packages to jersey.config.server.provider.packages in the web.xml

Injection of an EJB into a web java class under JBoss 7.1.1

I am trying to build a website using JBoss 7.1.1 and RESTeasy. I have managed to constructed and deploy and EAR with a both a WAR and an EJB-JAR contained within:
voyager-app.ear
META-INF/MANIFEST.MF
META-INF/application.xml
META-INF/jboss-app.xml
lib/voyager-lib.jar
voyager-adm.war
voyager-ejb.jar
voyager-web.war
So far things are very simple. voyager-adm.war & voyager-lib.jar are empty (just the manifest file) but I know that I'm going to have code for them shortly. There is just one Stateful EJB - HarbourMasterBean (with just a local interface) and a few Database Entity Beans in the EJB jar file:
voyager-ejb.jar
META-INF/MANIFEST.MF
META-INF/persistence.xml
com/nutrastat/voyager/db/HarbourMasterBean.class
com/nutrastat/voyager/db/HarbourMasterLocal.class
com/nutrastat/voyager/db/PortEntity.class
com/nutrastat/voyager/db/ShipEntity.class
As far as I can tell the EJBs deploy correctly because the database units are created and the log shows that the publication of some HarbourMaster references:
java:global/voyager-app/voyager-ejb/harbour-master!com.nutrastat.voyager.db.HarbourMasterLocal
java:app/voyager-ejb/harbour-master!com.nutrastat.voyager.db.HarbourMasterLocal
java:module/harbour-master!com.nutrastat.voyager.db.HarbourMasterLocal
java:global/voyager-app/voyager-ejb/harbour-master
java:app/voyager-ejb/harbour-master
java:module/harbour-master
The problem lies in getting the HarbourMaster EJB injected into my web bean. The reference to it is alway NULL no matter what I try.
voyager-web.war
META-INF/MANIFEST.MF
WEB-INF/web.xml
WEB-INF/classes/com/nutrastat/voyager/web/
WEB-INF/classes/com/nutrastat/voyager/web/Ships.class
WEB-INF/classes/com/nutrastat/voyager/web/VoyagerApplication.class
Ships.java:
#Path("fleet")
public class Ships {
protected transient final Logger log;
#EJB
private HarbourMasterLocal harbourMaster;
public Ships() {
log = LoggerFactory.getLogger(getClass());
}
#GET
#Path("ships")
#Produces({"text/plain"})
public String listShips() {
if (log.isDebugEnabled())
log.debug("Harbour master value: " + harbourMaster);
return "Harbour Master: " + harbourMaster;
}
}
<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" >
<display-name>Voyager Web Application</display-name>
<listener>
<listener-class>
org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
</listener-class>
</listener>
<servlet>
<servlet-name>Resteasy</servlet-name>
<servlet-class>
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
</servlet-class>
<init-param>
<param-name>
javax.ws.rs.Application
</param-name>
<param-value>
com.nutrastat.voyager.web.VoyagerApplication
</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Resteasy</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
I have been searching the web for an answer and read a number of places, both on StackOverflow and elsewhere that suggests is can be done, and that the problems lies with configuration. But they post only snippets and I'm never sure if I'm doing things correctly.
Many thanks for any help you can provide.
Dobbo
What happens if you do:
#Path("fleet")
#Singleton
public class Ships {