Problem injecting ejb in war

This problem have dogged me for one week but cant seem to know where the problem is.
i am creating an enterprise with war, ejb and jar.
i want both web clients and application client to share the code in ejb to ease maintainablility.
i have a jsf backing bean that is supposed to get some data from an enterprise bean in ejb.
the backing bean has this method
public class CategoryController {
@Stateful
public class CategoryControllerBean implements CategoryControllerRemote {
    @PersistenceUnit(unitName = "JNationForum-ejbPU")
    private EntityManagerFactory emf;
    private EntityManager getEntityManager() {
        return emf.createEntityManager();
public List<CategoryDetails> getCategorys(){
         EntityManager em = getEntityManager();
         List<Category> categorys=null;
         try{
            Query q = em.createQuery("select object(o) from Category as o");
            return copyCategorysToDetails(categorys=q.getResultList());
        } finally {
            em.close();
     private List<CategoryDetails> copyCategorysToDetails(List categorys) {
        List<CategoryDetails> detailsList = new ArrayList<CategoryDetails>();
        Iterator i = categorys.iterator();
        while (i.hasNext()) {
            Category category = (Category) i.next();
            CategoryDetails details = new CategoryDetails(
                    category.getCategorypk(),
                    category.getTitle(),
                    category.getDescription(),
                    category.getActive());
            detailsList.add(details);
        return detailsList;
}it brings this error
type Exception report
message
descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: com.sun.enterprise.InjectionException: Exception attempting to inject Unresolved Ejb-Ref com.safarisoftsolutions.jnationforum.war.bean.CategoryController/categoryControllerBean@jndi: com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean@null@com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean@Session@null into class com.safarisoftsolutions.jnationforum.war.bean.CategoryController
root cause
javax.faces.FacesException: com.sun.enterprise.InjectionException: Exception attempting to inject Unresolved Ejb-Ref com.safarisoftsolutions.jnationforum.war.bean.CategoryController/categoryControllerBean@jndi: com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean@null@com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean@Session@null into class com.safarisoftsolutions.jnationforum.war.bean.CategoryController
root cause
com.sun.enterprise.InjectionException: Exception attempting to inject Unresolved Ejb-Ref com.safarisoftsolutions.jnationforum.war.bean.CategoryController/categoryControllerBean@jndi: com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean@null@com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean@Session@null into class com.safarisoftsolutions.jnationforum.war.bean.CategoryController
root cause
javax.naming.NameNotFoundException: com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean#com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean not found
note The full stack traces of the exception and its root causes are available in the Sun Java System Application Server 9.1 logs.

This problem have dogged me for one week but cant seem to know where the problem is.
i am creating an enterprise with war, ejb and jar.
i want both web clients and application client to share the code in ejb to ease maintainablility.
i have a jsf backing bean that is supposed to get some data from an enterprise bean in ejb.
the backing bean has this method.package com.safarisoftsolutions.jnationforum.war.bean;
public class CategoryController {
    @EJB
    private CategoryControllerBean categoryControllerBean;
    public DataModel getCategorys() {
            model = new ListDataModel(categoryControllerBean.getCategorys());
            return model;
}from the above you can see am trying to get a list from categoryControllerBean.getCategorys() which is a enterprise bean whose code is
public class CategoryController {
@Stateful
public class CategoryControllerBean implements CategoryControllerRemote {
    @PersistenceUnit(unitName = "JNationForum-ejbPU")
    private EntityManagerFactory emf;
    private EntityManager getEntityManager() {
        return emf.createEntityManager();
public List<CategoryDetails> getCategorys(){
         EntityManager em = getEntityManager();
         List<Category> categorys=null;
         try{
            Query q = em.createQuery("select object(o) from Category as o");
            return copyCategorysToDetails(categorys=q.getResultList());
        } finally {
            em.close();
     private List<CategoryDetails> copyCategorysToDetails(List categorys) {
        List<CategoryDetails> detailsList = new ArrayList<CategoryDetails>();
        Iterator i = categorys.iterator();
        while (i.hasNext()) {
            Category category = (Category) i.next();
            CategoryDetails details = new CategoryDetails(
                    category.getCategorypk(),
                    category.getTitle(),
                    category.getDescription(),
                    category.getActive());
            detailsList.add(details);
        return detailsList;
}it brings this error
type Exception report
message
descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: com.sun.enterprise.InjectionException: Exception attempting to inject Unresolved Ejb-Ref com.safarisoftsolutions.jnationforum.war.bean.CategoryController/categoryControllerBean@jndi: com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean@null@com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean@Session@null into class com.safarisoftsolutions.jnationforum.war.bean.CategoryController
root cause
javax.faces.FacesException: com.sun.enterprise.InjectionException: Exception attempting to inject Unresolved Ejb-Ref com.safarisoftsolutions.jnationforum.war.bean.CategoryController/categoryControllerBean@jndi: com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean@null@com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean@Session@null into class com.safarisoftsolutions.jnationforum.war.bean.CategoryController
root cause
com.sun.enterprise.InjectionException: Exception attempting to inject Unresolved Ejb-Ref com.safarisoftsolutions.jnationforum.war.bean.CategoryController/categoryControllerBean@jndi: com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean@null@com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean@Session@null into class com.safarisoftsolutions.jnationforum.war.bean.CategoryController
root cause
javax.naming.NameNotFoundException: com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean#com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean not found
note The full stack traces of the exception and its root causes are available in the Sun Java System Application Server 9.1 logs.

Similar Messages

  • How to inject ejb in servlet

    hi all
    How to inject ejb in servlet ?
    please explain how to config my servlet and my paroject
    I have an ear file with two jar files
    Thanks in advance

    hi
    I have this error in my project
    I have an ear file ,two war file and three jar file in it
    and I did configuration
    but there was this error
    14:19:45,398 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[conference-servlet].[enterLet]] Allocate exception for servlet enterLet: javax.naming.NameNotFoundException: ITrmnlAuthenticationBL not bound
    @Remote
    public interface ITrmnlAuthenticationBL{
    @Stateless
    public class TrmnlAuthenticationBL implements ITrmnlAuthenticationBL{
    public class EnterLet extends HttpServlet {
         @EJB(mappedName = "ITrmnlAuthenticationBL")
         private ITrmnlAuthenticationBL trmnlMg;
    please explain my mistake

  • Injecting ejbs via @Resource

    Hi all,
    I have an ejb that injects a helper ejb like
    @EJB
    Helper help; and whose business method calls the helper beans business method. This works fine.
    Now I try to inject the helper ejb as
    @Resource(name="Helper") 
    Helper help; The first call of the ejb's business method from the client works fine, but the second one throws the following exception (extract):
    org.omg.CORBA.BAD_OPERATION: The delegate has not been set!
    Please, can someone, who has an ejb that injects another ejb, check if he gets the same problem when @EJB is replaced through something like @Resource(name = ...).
    Thanks in advance.
    I googled for the error message and found search results dating from around 2004 where the error was due to a bug in the Java-IDL mapping of an old java version. I'm working with glassfish v2 and java 1.6.

    Hi, thanks for your reply.
    Is there a particular behavior you would like that you don't think is available when using @EJB?No. I read in "EJB 3 in action", 5.2.1 that @Resource can "be used for [...] environment entries, ORB reference and even EJB references" and just tried it out.

  • Injecting EJB to JSF Converter

    Is it possible to inject EJB (or at least EntityManager) to JSF Converter or Validator?
    I don't know if i'm missing something or is it just impossible - it works when injecting EJB into Managed Bean.
    Thanks.
    S&#322;awek S.

    Slawek_Sobotka wrote:
    Thanks.
    So I'll redefine my question to be problem oriented:
    I have SelectItem that contains Address object.
    I have implemented AddressConverter so that it converts Adress to String simply by using it's id.
    How to convert back: from string (address's id) do Address object?Map it. Two general ways are mentioned here: [http://balusc.blogspot.com/2007/09/objects-in-hselectonemenu.html].
    I would like to load it form DB...That's a bit too expensive for less or more static data.
    Another solutions are:
    - SelectItem should contain address.id instead of address. Than no converter is need. My ManagedBean is reposnsible for translating ids do entities. Works but primitive.JSF can't help that HTTP/HTML only understands Strings (by the way, primitives are also already implicitly converted by EL, you only don't know that).
    - Converter is created by factory method of Managed Bean. MB sets address list to the converter while creating it. List shouldn't be huge if it is used in GUI.
    drawback: loading list in BB twice because converter is used while rendering and while decoding.
    - In converter try to possess MB that has EJB and call method that reutrns entities, sth like this: facesContext.getApplication().getELResolver()...Reloading static data on every request makes als no sense.
    Retoric question: what for are useful JSF Converters?To convert between Object and String, so that it can be passed through HTTP request/response and displayed/taken in HTML.

  • How am I able to use an injected EJB in a Managed Bean Constructor?

    JSF 1.2
    EJB 3.0
    Glassfish v1
    Summary:
    Managed bean injected EJB is null when referencing EJB var in constructor.
    Details:
    In my managed bean, I have a constructor that tries to reference an injected EJB, such as:
    public class CustomerBean implements Serializable {
    @EJB private CustomerSessionRemote customerSessionRemote;
    public CustomerBean() {
    List<CustomerRow> results = customerSessionRemote.getCustomerList();
    }The call within the constructor to customerSessionRemote is null - I've double checked this in Netbeans 5.5.
    How am I able to use an injected EJB in a Managed Bean Constructor?
    Thanks,
    --Todd                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    OK, I was reading the article Web Tier to Go With Java EE 5: A Look at Resource Injection and I understand your statement too.
    Is there any way possible to Inject the EJB prior to the bean instance creation at all?
    Maybe, I need to approach it with the old fashion Java EE 1.4 route and using JNDI in the PostConstruct annotated method to reference the EJB in the managed bean.
    This had to been thought out before, I don't understand why a manged bean's life cycle places any injections at the end of the bean creation.
    Also, now that I understand that the @PostConstruct annotated method will be called by the container after the bean has been constructed and before any business methods of the bean are executed.
    I am trying to reference my EJB as part of the creation of the managed bean.
    What happens: the JSF page loads the managed bean and I need to populate a listbox component with data from an EJB.
    When I try to make the call to the EJB in the listbox setter method, the EJB reference is null.
    Now, I'm not for sure if the @PostConstruct annotation is going to work... hmmmm.
    ** Figured it out. ** I just needed to move the EJB logic that was still in the setter of the component I wanted to populate into the annotated PostConstruct method.

  • Problem with EJB skeleton classloader

    Hi
    We have been migrating an enterprise application from Weblogic 7 to 9.2 and experienced strange problem with EJBs. Our EAR contains (beside the other elements) an EJB module with EJBs and some common POJO classes inside. At the deploy and run phase everything seems working fine, but when the remote client invokes a method which receives one of the common classes as a parameter we get ClassNotFoundException on the server side (talking precisely, the exception is thrown from the EJB skeleton, trying to unmarshall the parameter).
    It seems that our EJB's skeletons do not see the classes from EAR. We have tried moving the common classes to the APP-INF/lib directory or placing them at the root of EAR archive and adding reference in Manifest file of EJB module and it won't help.
    The only workaround we've found is to add the missing classes to the server classpath but this is unacceptable (however, it works).
    We are not using any custom classloader hierarchy.
    The other JARs have no problem loading the content of our EJB module (including the common classes, which cause the problem).
    So, why is the RMI classloader ommiting our application contents?

    The problem was fixed by upgrading to version 9.2.1

  • Best way to inject EJB's in Struts 2

    Hi all,
    I'd like to ask you what do you think is the best way to inject EJB's in Struts 2 Actions (and perhaps other struts classes such as type converters).
    I've read and implemented both a Struts 2 Interceptor and used CDI. About CDI I've read there's a discussion whether the injected resource should be a private field or injected through the constructor which would help testing.
    Personally I seem to prefer CDI as it looks a bit simpler after you are familiar a bit with the technology.
    What is your preferred solution and why?

    Make sure you are using JDeveloper with a "regular Oracle DB" and not Oracle XE - Oracle XE doesn't have support for JPublisher.
    And make sure you are trying to invoke this from the database navigator window and not from the connection manager of your application.
    Anton - I think you are mixing JPublisher with something else - maybe with Java stored procedures?
    JPublisher just creates a JDBC wrapper that calls the functions in the DB - it doesn't run inside the DB so I don't get your point about the mini JVM?
    So it basically does exactly what you recommended: "access PL/SQL procedures from java directly?"

  • Injection @EJB  x  InitialContextLookup

    Hello all,
    what is the "lookup" correspondent to this injection:
    @EJB (mappedName="corbaname:iiop:jupiter:3700#ejb/package.HelloRemote")
    Are the following lines?
    InitialContext ic = new InitialContext();
    HelloRemote hello = (HelloRemote) ic.lookup("corbaname:iiop:jupiter:3700#ejb/package.HelloWorld");
    Why these lines dont work? The injection woks fine, but these lines produces an exception:
    "javax.naming.NameNotFoundException [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]"
    I'm trying for one week now to do this dynamic lookup without succeeding. Please, what am I missing?

    If you're running within a Java EE component the portable way to retrieve the EJB is
    to use a component environment lookup, not a direct global lookup. Just add a
    name() attribute to your @EJB.
    @EJB (name="myejbref", mappedName="corbaname:iiop:jupiter:3700#ejb/package.HelloRemote")
    If the lookup is within an EJB, you can use SessionContext.lookup("myejbref");
    Otherwise, instantiate the no-arg InitialContext and lookup ("java:comp/env/myejbref")
    Whenever the code attempts to bypass the Java EE component environment, it opens
    itself up to portability issues. In this case, we try to support many variations of
    direct global JNDI lookups, but Remote 3.0 Interfaces are not direct CosNaming objects,
    so lookup("corbaname:iiop:...") will not work.
    If you have to pass a dynamic string to the lookup you can try the same approach as
    is recommended for non-Java EE environments, where you create a special
    InitialContext that is configured to point to a particular naming service :
    https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#nonJavaEEwebcontainerRemoteEJB
    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Deploy EAR. Both ejb and war share classes?

    how do you package an ear that has both ejbs and wars that share a common set of classes.
    I have read through all the messages that state to add the Manifest entry Class-Path.
    I've added it to the war, ejb and ear Class-Path and I still get the same NoClassDefFoundError.
    Does anybody truely know how to get this to work? I've tried many things, and it sounds like this should work/.....?????

    Hi Madhav,
    You need to specify Class-Path in ejb-jar MANIFEST.MF,
    not in the ear.
    Regards,
    Slava Imeshev
    "Madhav Inamti" <[email protected]> wrote in message
    news:[email protected]..
    >
    I have tried the manifest classpath too and it just does not work. I had alibrary
    jar specified the ear's manifest classpath and the library jar in the earfile
    too. This should have made the ear classloader load the library jar.Didn't work.
    Does anybody on this newsgroup know about this .. ?
    "Dimitri I. Rakitine" <[email protected]> wrote:
    Since ejb classloader is a parent of a webapp classloader, you should
    only
    add these jar's to your ejb-jar Class-Path Manifest entry. Make sure
    your dependencies
    hierarchy is ok - NoClassDefFoundError usually means that the class
    itself was found,
    but not it's dependent class(es).
    Michael <[email protected]> wrote:
    how do you package an ear that has both ejbs and wars that share acommon set of classes.
    I have read through all the messages that state to add the Manifestentry Class-Path.
    I've added it to the war, ejb and ear Class-Path and I still get thesame NoClassDefFoundError.
    Does anybody truely know how to get this to work? I've tried many
    things,
    and it sounds like this should work/.....?????
    Dimitri

  • Dependency Injection Problem in EJB 3.0

    Hello.
    I've been trying to get an example of java dependency injection working in JBoss 4.0.5.GA. I've installed it with EJB 3.0 support.
    The problem is that if I try to use the injected resource, I get a null pointer exception.
    The example I'm trying is a very short and simple one. Shouldn't be hard to figure out what is going wrong. Here it goes:
    [root]\src\hello\MessageServlet.java:
    package hello;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.List;
    import java.util.ListIterator;
    import javax.naming.InitialContext;
    import javax.annotation.*;
    public class MessageServlet extends HttpServlet {
         @Resource (mappedName="java:/DefaultDS")
         javax.sql.DataSource ejb30DB;
         public void init () throws ServletException {
         public void service(HttpServletRequest request, HttpServletResponse response)
                   throws IOException, ServletException {
              boolean injectedLookingGood = false;
              boolean notInjectedLookingGood = false;
              try {
                   java.sql.Connection conn = ejb30DB.getConnection();
                   conn.close();
                   injectedLookingGood = true;
              } catch(Exception e) {
                   e.printStackTrace();
              try {
                   InitialContext ic = new InitialContext();
                   javax.sql.DataSource ds = (javax.sql.DataSource)ic.lookup("java:/DefaultDS");
                   java.sql.Connection conn = ds.getConnection();
                   conn.close();
                   notInjectedLookingGood = true;
              } catch(Exception e) {
                   e.printStackTrace();
              response.setContentType("text/html");
              ServletOutputStream out = response.getOutputStream();
              out.println("<html>");
              out.println("<head><title>Hello World</title></head>");
              out.println("<body>");
              out.println("<h1>Hello World</h1>");
              out.println("<form action=\"HelloWorld\" method=\"get\">");
              out.print("Injected DataSource is looking ");
              if(injectedLookingGood) {
                   out.println("good <br>");
              else {
                   out.println("bad <br>");
              out.print("Not-Injected DataSource is looking ");
              if(notInjectedLookingGood) {
                   out.println("good <br/>");
              else {
                   out.println("bad <br/>");
              out.println("<input type=\"submit\" value=\"Test Some More\">");
              out.println("</form>");
              out.println("</body>");
              out.println("</html>");
    [root]\etc\META-INF\web.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
    "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
    <web-app>
    <display-name>HelloWorldWAR</display-name>
    <servlet>
    <display-name>HelloWorld</display-name>
    <servlet-name>HelloWorldServlet</servlet-name>
    <servlet-class>hello.MessageServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>HelloWorldServlet</servlet-name>
    <url-pattern>/servlet/HelloWorld</url-pattern>
    </servlet-mapping>
    </web-app>
    [root]\etc\META-INF\application.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <application xmlns="http://java.sun.com/xml/ns/j2ee" version="1.4"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com /xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
    <display-name>HelloWorld</display-name>
    <description>Application description</description>
    <module>
    <web>
    <web-uri>web-ejb3.war</web-uri>
    <context-root>HelloWorld</context-root>
    </web>
    </module>
    </application>
    [root]\build.xml:
    <project name="HelloWorld" default="all" basedir=".">
    <!-- Name of project and version -->
    <property name="proj.name" value="HelloWorld"/>
    <property name="proj.version" value="1.0"/>
    <!-- Global properties for thid build -->
    <property name="src.dir" value="${basedir}/src"/>
    <property name="build.dir" value="${basedir}/bin"/>
    <property name="lib.dir" value="${basedir}/lib"/>
    <property name="build.classes.dir" value="${build.dir}/classes"/>
    <property name="build.jar.dir" value="${build.dir}/jar"/>
    <property name="src.etc.dir" value="${basedir}/etc"/>
    <property name="meta-inf.dir" value="${src.etc.dir}/META-INF"/>
    <!-- The build classpath -->
    <path id="build.classpath">
    <fileset dir="${lib.dir}">
    <include name="**/*.jar"/>
    <include name="**/*.zip"/>
    </fileset>
    </path>
    <!-- Useful shortcuts -->
    <patternset id="meta.files">
    <include name="**/*.xml" />
    <include name="**/*.properties"/>
    </patternset>
    <target name="prepare">
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${build.classes.dir}"/>
    <mkdir dir="${build.jar.dir}"/>
    </target>
    <target name="compile" depends="prepare">
    <javac destdir="${build.classes.dir}"
    classpathref="build.classpath"
    debug="on">
    <src path="${src.dir}"/>
    </javac>
    </target>
    <target name="package-web" depends="compile">
    <war warfile="${build.dir}/jar/web-ejb3.war"
    webxml="${meta-inf.dir}/web.xml">
    <classes dir="${build.dir}/classes">
    <include name="**/*Servlet.class"/>
    </classes>
    </war>
    </target>
    <!-- Creates an ear file containing the web client war. -->
    <target name="assemble-app">
    <ear destfile="${build.jar.dir}/HelloWorld.ear" appxml="${meta-inf.dir}/application.xml">
    <fileset dir="${build.dir}/jar"
    includes="*.war"/>
    </ear>
    </target>
    <target name="clean">
    <delete dir="${build.dir}" />
    </target>
    <target name="all">
    <antcall target="clean" />
    <antcall target="package-web" />
    <antcall target="assemble-app" />
    </target>
    </project>
    Any help would be apreciated.
    Thanks in advance,
    Hugo Oliveira
    [email protected]

    Hello Ken.
    I gess dependency injection is unnavailable in servlets as of this moment. I conducted another test using a session bean that injects and tests the DataSource and a servlet calling the session bean via a refference obtained from InitialContext. It worked OK.
    Here's the code:
    [root]/src/hello/MessageHandler.java:
    package hello;
    public interface MessageHandler {
         public boolean testInjection();
    [root]/src/hello/MessageHandlerBean.java:
    package hello;
    import javax.ejb.Stateless;
    import javax.persistence.*;
    import java.util.List;
    import javax.annotation.*;
    @Stateless
    public class MessageHandlerBean implements MessageHandler {
         @Resource (mappedName="java:/DefaultDS")
         private javax.sql.DataSource ds;     
         public boolean testInjection() {
              try {
                   java.sql.Connection conn = ds.getConnection();
                   conn.close();
                   return true;
              } catch(Exception e) {
                   e.printStackTrace();
              return false;
    [root]/src/hello/MessageServlet.java:
    package hello;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.List;
    import java.util.ListIterator;
    import javax.naming.InitialContext;
    import javax.annotation.*;
    public class MessageServlet extends HttpServlet {
         public void init () throws ServletException {
         public void service(HttpServletRequest request, HttpServletResponse response)
                   throws IOException, ServletException {
              boolean injectedLookingGood = false;
              try {
                   InitialContext ic = new InitialContext();
                   MessageHandler mh = (MessageHandler)ic.lookup("HelloWorld/MessageHandlerBean/local");
                   injectedLookingGood = mh.testInjection();
              } catch(Exception e) {
                   e.printStackTrace();
              response.setContentType("text/html");
              ServletOutputStream out = response.getOutputStream();
              out.println("<html>");
              out.println("<head><title>Hello World</title></head>");
              out.println("<body>");
              out.println("<h1>Hello World</h1>");
              out.println("<form action=\"HelloWorld\" method=\"get\">");
              out.print("Injected DataSource is looking ");
              if(injectedLookingGood) {
                   out.println("good <br>");
              else {
                   out.println("bad <br>");
              out.println("<input type=\"submit\" value=\"Test Some More\">");
              out.println("</form>");
              out.println("</body>");
              out.println("</html>");
    [root]/etc/META-INF/application.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <application xmlns="http://java.sun.com/xml/ns/j2ee" version="1.4"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com /xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
    <display-name>HelloWorld</display-name>
    <description>Application description</description>
    <module>
    <ejb>HelloWorld.ejb3</ejb>
    </module>
    <module>
    <web>
    <web-uri>web-ejb3.war</web-uri>
    <context-root>HelloWorld</context-root>
    </web>
    </module>
    </application>
    [root]/etc/META-INF/web.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
    "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
    <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">
    <display-name>HelloWorldWAR</display-name>
    <servlet>
    <display-name>HelloWorld</display-name>
    <servlet-name>HelloWorldServlet</servlet-name>
    <servlet-class>hello.MessageServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>HelloWorldServlet</servlet-name>
    <url-pattern>/servlet/HelloWorld</url-pattern>
    </servlet-mapping>
    </web-app>
    [root]/build.xml:
    <project name="HelloWorld" default="all" basedir=".">
    <!-- Name of project and version -->
    <property name="proj.name" value="HelloWorld"/>
    <property name="proj.version" value="1.0"/>
    <!-- Global properties for thid build -->
    <property name="src.dir" value="${basedir}/src"/>
    <property name="build.dir" value="${basedir}/bin"/>
    <property name="lib.dir" value="${basedir}/lib"/>
    <property name="build.classes.dir" value="${build.dir}/classes"/>
    <property name="build.jar.dir" value="${build.dir}/jar"/>
    <property name="src.etc.dir" value="${basedir}/etc"/>
    <property name="meta-inf.dir" value="${src.etc.dir}/META-INF"/>
    <!-- The build classpath -->
    <path id="build.classpath">
    <fileset dir="${lib.dir}">
    <include name="**/*.jar"/>
    <include name="**/*.zip"/>
    </fileset>
    </path>
    <!-- Useful shortcuts -->
    <patternset id="meta.files">
    <include name="**/*.xml" />
    <include name="**/*.properties"/>
    </patternset>
    <target name="prepare">
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${build.classes.dir}"/>
    <mkdir dir="${build.jar.dir}"/>
    </target>
    <target name="compile" depends="prepare">
    <javac destdir="${build.classes.dir}"
    classpathref="build.classpath"
    debug="on">
    <src path="${src.dir}"/>
    </javac>
    </target>
    <target name="package-ejb" depends="compile">
    <jar jarfile="${build.jar.dir}/HelloWorld.ejb3">
    <fileset dir="${build.classes.dir}">
    <include name="**/*.class"/>
    </fileset>
    <!--
         <metainf dir="${meta-inf.dir}">
    <include name="persistence.xml"/>
    </metainf>
    -->
    </jar>
    </target>
    <target name="package-web" depends="compile">
    <war warfile="${build.dir}/jar/web-ejb3.war"
    webxml="${meta-inf.dir}/web.xml">
    <!--
    <fileset dir="web">
    <include name="**/*"/>
    </fileset>
    -->
    <!--
    <webinf dir="dd/web">
    <include name="jboss-web.xml"/>
    </webinf>
    -->
    <classes dir="${build.dir}/classes">
    <include name="**/*Servlet.class"/>
    </classes>
    </war>
    </target>
    <!-- Creates an ear file containing the ejb jars and the web client war. -->
    <target name="assemble-app">
    <ear destfile="${build.jar.dir}/HelloWorld.ear" appxml="${meta-inf.dir}/application.xml">
    <fileset dir="${build.dir}/jar"
    includes="*.ejb3,*.war"/>
    </ear>
    <!-- <delete file="${build.dir}/jar/web-ejb3.war"/>
    <delete dir="${build.dir}/classes"/> -->
    </target>
    <target name="clean">
    <delete dir="${build.dir}" />
    </target>
    <target name="all">
    <antcall target="clean" />
    <antcall target="package-ejb" />
    <antcall target="package-web" />
    <antcall target="assemble-app" />
    </target>
    </project>
    Thanks,
    Hugo Oliveira
    [email protected]

  • Problem: Editing a deployment descriptor of an EJB or WAR inside of an EAR sends things to hell

    Hello,
    I've got an EAR with utility classes in lib/ (like log4j and some other
    goodies).
    Inside my EJBs, I have manifests that have class-path entries that reference
    this and they all work upon initial load (I when they don't work because my
    beans don't load).
    When I edit my descriptors using the WebLogic console and persist my
    changes, my EJBs crap out because they can no longer load log4j. When I
    shutdown WebLogic and looked at the manifest inside the EJB inside of the
    EAR, sure enough, the class-path entry that kept the whole thing working was
    gone. WebLogic decided to instead detail a bunch of classes.
    Any workaround for this (other than to include all classes in all EJBs)?
    This prevents customers and deployers from doing their jobs. :(
    How do I report this to BEA? I poked around the website and could nary find
    a "report bug" link.
    thanks,
    greg

    Yes - getting to support should be easier ...
    www.bea.com -> Services -> Customer Support Services -> Learn More about WebSupport
    -> Register for Web Account
    Then you can follow the WebSupport link at the bottom of any page.
    Mike
    "Gregory Gerard" <[email protected]> wrote:
    Hello,
    I've got an EAR with utility classes in lib/ (like log4j and some other
    goodies).
    Inside my EJBs, I have manifests that have class-path entries that reference
    this and they all work upon initial load (I when they don't work because
    my
    beans don't load).
    When I edit my descriptors using the WebLogic console and persist my
    changes, my EJBs crap out because they can no longer load log4j. When
    I
    shutdown WebLogic and looked at the manifest inside the EJB inside of
    the
    EAR, sure enough, the class-path entry that kept the whole thing working
    was
    gone. WebLogic decided to instead detail a bunch of classes.
    Any workaround for this (other than to include all classes in all EJBs)?
    This prevents customers and deployers from doing their jobs. :(
    How do I report this to BEA? I poked around the website and could nary
    find
    a "report bug" link.
    thanks,
    greg

  • Common JAR file between EJB and WAR inside an EAR

    Hi,
    I'm trying to deploy an EAR application outside the development environment and I have the following problem.
    My EAR has the following structure :
    application.ear
    |-- ejbs.jar
    |-- web.war
    Inside the WAR, in /WEB-INF/lib/, I have a set of JAR files that are used by the Web app and also, of course, by the EJB.
    During the deployment step, EJB module cannot be deployed because it miss some classes into the classpath.
    I think it is a common problem in J2EE development, so does someone has a solution for this problem ?
    Please note I'm using Macromedia JRun 4 SP1 on Windows XP.
    Regards,
    Damien.

    Ok,
    I have found a solution that seems elegant to me. I'm going to try and explain...
    My appli.jar EJB module and my appli.war Web module are using both two JAR, let's say common.jar and util.jar.
    The way to share those JAR between the two modules is to have the following structure for the EAR :
    appli.ear
      |-- appli.jar
      |-- appli.war
      |-- common.jar
      |-- util.jar
      |-- META-INF
           |-- application.xml
           |-- manifest.mfIn this structure :
    * the common.jar and the util.jar are not part of the WAR (/web-inf/lib)
    * the manifest.mf file has the following content :
    Manifest-Version: 1.0
    Created-By: My Application
    Class-Path: common.jar util.jarPlease note that space is used as separator for the classpath entry to allow independancy from OS.
    And you know what ? It works ! Well, on Macromedia JRun 4.0 SP1 and on Windows XP but I hope it works on other platforms.
    I hope it will help a lot of people because I spent a lot of time before to find a solution !
    Regards,
    Damien.

  • Persistence shared across EJB and WAR projects

    Hi,
    I have created an Enteprise Application in netbeans which has an EJB project and a web archive. This may be expanded further at a later time by having an application client as well. I am still fairly new to this so you'll have to forgive me if this is a simple problem. I have a persistence unit (persistence.xml) that I need to share across both WAR and EJB, but so far am not having much luck. I have read various responses and they say I should have the EAR constructed as the following:
    project.ear
    =======
    META-INF/MANIFEST.MF
    lib/persistence.jar
    ---> META-INF
    ---> META-INF/persistence.xml
    project-ejb.jar
    project-war.war
    When I try and compile it though I get the following messages from both EE modules:
    Note: The persistence xml file [META-INF/persistence.xml] was not found. NO GENERATION will occur!! Please ensure a persistence xml file is available either from the CLASS_OUTPUT directory [META-INF/persistence.xml] or using the eclipselink.persistencexml property to specify its location.
    I have tried copying the persistence.xml into the main META-INF directory in the EAR file and setting the eclipselink.persistencexml=META-INF/persistence.xml, but it still shows the same thing. Is this a classpath issue or is there something else wrong?
    Many thanks

    The EAR is a good idea, but you put the META-INF/persistence.xml in your ejb module. The EJB is where you want to do all your (container managed) transactional stuff, so make calls into your EJBs from the WAR in stead of trying to share a persistence unit across modules.

  • Problem accessing ejb from servlet

    Hi,
    I'm aving a problem accessing a stateful session bean from a servlet. I'm using a jndi lookup to do it because I need that a client has its own bean reference...
    My code into the service method is:
    InitialContext ctx;
    try {
    ctx = new InitialContext();
    carrelloService = (CarrelloLocal)ctx.lookup("java:comp/env/ejb/Carrello");
    and I have a reference to EJB into web.xml:
    <ejb-local-ref>
    <ejb-ref-name>ejb/Carrello</ejb-ref-name>
    <ejb-ref-type>Session</ejb-ref-type>
    <local-home></local-home>
    <local>carrello.model.CarrelloLocal</local>
    </ejb-local-ref>
    If I use @EJB annotation to inject the servlet, it works fine.
    Instead using jndi lookup throws a NamingException because it doesn't find java:comp/env/ejb/Carrello entry.
    Any idea about the problem?

    Here's something simple that I have that works:
    <p> </p>
    SimpleBean
    <p> </p>
    @Stateless(name="SimpleBean")
    public class SimpleBeanBean implements SimpleBeanLocal {
    <p> </p>
    web.xml; -- note I use a whacko ejb-ref-name just to make it obvious where I'm using it.
    <p> </p>
        <ejb-local-ref>
            <ejb-ref-name>ejb_mapping_doodad/SimpleBean</ejb-ref-name>
            <ejb-ref-type>Session</ejb-ref-type>
            <local>sab.otn681398.ejb.SimpleBeanLocal</local>
        </ejb-local-ref><p> </p>
    servlet:
    <p> </p>
    package sab.otn681398.web;
    import java.io.IOException;
    import java.io.PrintWriter;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import sab.otn681398.ejb.SimpleBeanLocal;
    public class TestServlet extends HttpServlet  {
        private static final String CONTENT_TYPE = "text/html; charset=windows-1252";
        private static final String SIMPLE_BEAN_JNDI = "ejb_mapping_doodad/ASimpleBean";
        private final boolean USEENC = true;
        private SimpleBeanLocal simple = null;
        public void init(ServletConfig config) throws ServletException {
            super.init(config);
        public void doGet(HttpServletRequest request,
                          HttpServletResponse response) throws ServletException, IOException {
            response.setContentType(CONTENT_TYPE);
            PrintWriter out = response.getWriter();
             try {
                if(simple==null) {
                    simple = createSimple();
            } catch(NamingException ne) {
                throw new ServletException("Error in looking up the EJB", ne);
            out.println("<html>");
            out.println("<head><title>TestServlet</title></head>");
            out.println("<body>");
            out.printf("&lt;p&gt;The %s bean has been hit: %s times&lt;/p&gt;", simple, simple.getHitCount());
            out.println("</body></html>");
            out.close();
        private SimpleBeanLocal createSimple() throws NamingException {
          return (USEENC==true? createSimpleViaENC(): createSimpleViaName());
        private SimpleBeanLocal createSimpleViaENC() throws NamingException {
            InitialContext ic = new InitialContext();
            SimpleBeanLocal simple = (SimpleBeanLocal)ic.lookup("java:comp/env/" + SIMPLE_BEAN_JNDI);
            return simple;
        private SimpleBeanLocal createSimpleViaName() throws NamingException {
            InitialContext ic = new InitialContext();
            SimpleBeanLocal simple = (SimpleBeanLocal)ic.lookup(SIMPLE_BEAN_JNDI);
            return simple;
    }<p> </p>
    -steve-

  • Problem deploying EJB to Oracle 8.1.7

    Hi,
    I'm facing a problem while deploying EJB on to Oracle 8i.
    I'm using oracle 8.1.7 under Linux (RedHat 7.0).
    Also I'm using JDeveloper 3.2.2 (working under Windows NT)
    JDeveloper came with JDK version 1.2.2, but I'm using
    JDK 1.3(to use connection pooling).
    Classes compiled and says it is error free.
    But when I try to deploy this it gives me an error message saying
    Compilation errors in oracle/aurora/ejb/gen/dbAccess_dbEJB/EjbHome_DataAccessEJBHome:ORA-29535: source requires recompilation
    oracle/aurora/ejb/gen/dbAccess_dbEJB/EjbHome_DataAccessEJBHome:50: Exception java.lang.Exception must be caught, or it must be declared in the throws clause of this method.
    Info: 1 errors
    *** Errors occurred while deploying the EJB to 8i JVM ***
    ie. When I start deploying
    after it generates descriptors it displays message as below
    Reading Deployment Descriptor...done
    Verifying Deployment Descriptor...done
    Gathering users...done
    Generating Comm Stubs...................................................done
    Compiling Stubs...done
    Generating Jar File...done
    Loading EJB Jar file and Comm Stubs Jar file...done
    Generating EJBHome and EJBObject on the server...
    Compilation errors in oracle/aurora/ejb/gen/dbAccess_dbEJB/EjbHome_DataAccessEJBHome:ORA-29535: source requires recompilation
    oracle/aurora/ejb/gen/dbAccess_dbEJB/EjbHome_DataAccessEJBHome:50: Exception java.lang.Exception must be caught, or it must be declared in the throws clause of this method.
    Info: 1 errors
    *** Errors occurred while deploying the EJB to 8i JVM ***
    *** Deployment completed ***
    Later I copied aurora_client.zip from Linux on to JDeveloper version.
    Still I get the same error.
    Any idea?
    Expecting your valuable suggestions.
    Thanks,
    Rajeev Mancheril.
    null

    I am wondering about the classes in the database. This is from metalink.
    SELECT count(*)
    FROM dba_objects
    WHERE object_type LIKE '%JAVA%';
    If the above query returns a number < 4000, the installation was not
    successful.
    The query below checks for any invalid Java classes using a Java stored procedure:
    SELECT dbms_java.longname(name)
    FROM sys.obj$
    WHERE type# = 29 and status != 1;
    If the above query fails or returns any rows, then something is wrong with the JVM installation.
    You can also test the Jserver by using the examples in
    $OH/javavm/demo/examples/corba/basic/helloworld
    or
    $OH/javavm/demo/examples/ejb/basic/helloworld
    To compile classes in the database
    Alter Java Class " Name of the java class" compile;
    Linda
    null

Maybe you are looking for

  • I don't want my mouse to pick up my tabs or open them in other windows? How can I change the settings?

    My mouse keeps picking up web tabs and I don't want it do that or open them in other windows.

  • The dreaded lollipop

    I have read as much as I can about this topic...and nothing seems to work. I have several new G4 emacs in a computer lab...they are all 256 mb RAM...actually, some are 512. We are getting the spinning lollipop/ball . I have emptied the recent items a

  • FIX FOUND for iPod classic refusing to play mp3s

    I have several albums on my iPod that I've ripped myself from my CDs (using EAC+Lame to rip, foobar2k to calculate replay gain and mp3tag to clean up tags and convert RPG to iTunes soundcheck). These files play fine on iTunes and any other program, a

  • File comparaison works on win32 JVM, not on 64bit solaris JVM

    Hi all! I have the following code comparing 2 files. It works on win2000 but doesnt work on unix solaris. (same JVM version) win32 JVM is 32 bit, solaris JVM 64 bit private boolean fichierIdentiqueBytePourByte( InputStream in1, InputStream in2 ) thro

  • Different Safari and system language

    Hi, I would like to ask, if it is possible to have different system language (System Preferences > Language/Religion/Preferred Languages) and Safari language. The problem is, that I want to have my Mac in english (Preferred Language - English), but S