facebook

How to make visible a ejb-jar file to a war file?

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #289523 Reply

    pmrenaud
    Member

    Hi Experts,
    I’ve created a bean project which use a JSP/Servlet client and EJB objects (sessionBean). Both are on the same server. From them, i’ve created a war and a ejb-jar…
    but i’m having a problem. The war file seems unable to see the ejb-jar once deployed. In fact the only way to get ejb-jar visible from the war is to add it into the classpath of the war file. But i didn’t see any example or tutorial who talk about adding the ejb-jar into the classpath of the war.
    I’m using annotation according to this example: https://glassfish.dev.java.net/javaee5/ejb/examples/Sful.html.

    I’m using MyEclipse 6.x and a Glassfish server.

    ClientSessionRemote.java

    
    package com.imagem;
    
    import javax.ejb.Remote;
    
    @Remote
    public interface ClientSessionRemote {
    
        public java.lang.String SayHello();
        
    }
    

    ClientSession.java

    
    package com.imagem;
    
    import javax.ejb.Stateful;
    
    @Stateful
    public class ClientSession implements ClientSessionHome, ClientSessionRemote  {
    
        public String SayHello(){
              String msg="Hello! I am Session Bean";
              System.out.println(msg);
              return msg;
        }
    
    }
    

    Controller.java (servlet)

    
    public class Controller extends HttpServlet {
    
        @EJB 
        private ClientSessionRemote m_testClientSessionBean;
    
        ...code...
    
        public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
            PrintWriter out;
            response.setContentType("text/html");
            String title = "EJB Example";
            out = response.getWriter();
    
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Hello World Servlet!</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("<p align=\"center\"><font size=\"4\" color=\"#000080\">Servlet Calling Session Bean</font></p>");
            
            try{
                
                //ClientSessionRemote client = (ClientSessionRemote) new InitialContext().lookup("java:comp/env/StatefulClientSession");
                //ClientSessionRemote client = (ClientSessionRemote) new InitialContext().lookup(ClientSessionRemote.class.getName());
     
                //out.println("<p align=\"center\"> Message from Session Bean is: <b>" + client.SayHello() + "</b></p>"); 
                //System.out.println("Message = " + client.SayHello());
                
                out.println("<p align=\"center\"> Message from Session Bean is: <b>" + m_testClientSessionBean.SayHello() + "</b></p>"); 
            }
            catch(Exception CreateException){
                CreateException.printStackTrace();
            }
            
            out.println("<p align=\"center\"><a href=\"javascript:history.back()\">Go to Home</a></p>");
            out.println("</body>");
            out.println("</html>");
            out.close();
            
            
            
            
        }
    
        ...code...
    
    }
    

    any help would be appreciate!!!

    thks Mart

    #289545 Reply

    pmrenaud
    Member

    Okay,

    it seems my question isn’t clear…. (or too difficult). I have a Java Entreprise project. On a side, there is a web client (.war) and on the other side, there is a EJB (ejb .jar). Both are on the same glassfish server.
    Here are the questions:
    Do i need to include in the classpath the .war the ejb .jar? Or normally the .war file is supposed to see (or get access to) the ejb .jar project into the ejb container?

    hope someone’s gonna help me!!

    thks

    Mart.

    #289546 Reply

    pmrenaud
    Member

    sorry… let’s give a try: Do i need to include IN the classpath OF the .war file the ejb .jar file?

    #289777 Reply

    Loyal Water
    Member

    Moving to Off Topic >> Software Development.

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: How to make visible a ejb-jar file to a war file?

You must be logged in to post in the forum log in