ejb@glassfish.java.net

Re: war not see ejb jar...

From: Eliot Morrison <Eliot.Morrison_at_Sun.COM>
Date: Wed, 01 Oct 2008 14:24:47 -0700

Sorry --- ignore last message.

Eliot


Marina Vatkina wrote:
> Can you publish your application.xml?
>
> If you still use 2 separate deployments, make sure you package
> ClientSessionRemote into your war file.
>
> Regards,
> -marina
>
> Martin Renaud wrote:
>> This is exactly what i tought... and this is exactly what i've
>> done... without success!
>>
>> I'm working with MyEclipse. When comes time to deploy the project,
>> the ejb is compiled, packaged and deployed on the glassfish server.
>> And samething for the webclient.
>> If you consider I removed the ejb .jar reference from the classpath
>> of the .war... can you tell me what is going wrong with this code?
>> why i still having the error of ClassNotFound about the class
>> "com.imagem.ClientSessionRemote" when I run the web client on the web
>> browser (http://localhost:8080/BeanProjectWeb/index.jsp)?
>>
>> ClientSessionRemote.java
>> *Code:*
>>
>> package com.imagem;
>>
>> import javax.ejb.Remote;
>>
>> @Remote
>> public interface ClientSessionRemote {
>>
>> public java.lang.String SayHello();
>> }
>>
>>
>>
>> ClientSession.java
>> *Code:*
>>
>> package com.imagem;
>>
>> import javax.ejb.Stateful;
>>
>> @Stateful
>> public class ClientSession implements ClientSessionRemote {
>>
>> public String SayHello(){
>> String msg="Hello! I am Session Bean";
>> System.out.println(msg);
>> return msg;
>> }
>>
>> }
>>
>>
>>
>> Controller.java (servlet)
>> *Code:*
>>
>> public class Controller extends HttpServlet {
>>
>> @EJB
>> private ClientSessionRemote m_testClientSessionBean;
>>
>> ...some 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();
>> }
>>
>> ...some code...
>>
>> }
>>
>>
>>
>> thanks for help...
>>
>> Martin Renaud
>>
>>
>> On Wed, Oct 1, 2008 at 4:17 PM, Baptiste MATHUS <ml_at_batmat.net
>> <mailto:ml_at_batmat.net>> wrote:
>>
>> Remember we're on a public list and that there's some non-french
>> speakers. I'm no expert in the EJB/JavaEE area, I might not have be
>> clear about. So please take everything I say very cautiously.
>> You're wondering why you have to specify the classpath. I guess it
>> has something to do with deployment ordering: it seems quite logical
>> that your war won't be able to start if the ejb it depends on is not
>> present.
>>
>> So, at first deployment, I guess you respect ordering, that seems
>> logical.
>> But then, you war and your ejb jar stay in the server deploy dir.
>> Imagine you restart it. If the server sees some artifact needs some
>> other, then I guess it will build some tree to start artifacts (ejb
>> jar, war, ...) in the right order so that every goes OK.
>>
>> Is this more clear to you? Any expert to confirm above or warn that
>> I'm just blowing a fusd and correct it? :-)
>>
>>
>> Cheers.
>>
>> 2008/10/1 Martin Renaud <pm.renaud_at_gmail.com
>> <mailto:pm.renaud_at_gmail.com>>
>>
>> Génial... j'y jette un coup d'oeil.
>> Mais supposons que je désire plutôt créer d'une part un
>> web-client (.war) ainsi qu'un ejb (.jar)... sans pour autant
>> créer un package .ear ... et déployer ces deux packages sur le
>> serveur web... c'est possible!!!??!? Seulement, et c'est ce qui
>> me trouble un peu, c'est que je dois tout de même placer une
>> référence du package ejb-jar dans le classpath du package war.
>>
>> Ai-je bien compris?
>>
>> merci Baptiste!
>>
>> Martin Renaud
>>
>>
>> On Wed, Oct 1, 2008 at 3:59 PM, Baptiste MATHUS <ml_at_batmat.net
>> <mailto:ml_at_batmat.net>> wrote:
>>
>> Well, it's actually quite simple from my recent experience
>> (I only tested with many interdependent ejb modules though).
>>
>> Manually, it's something like this.
>> 1/ Create a directory that will contain all your ear data.
>> 2/ Put for example all your modules at the root (your many
>> wars and your ejb jar inside a directory)
>> 3/ Create a META-INF directory and put an application.xml
>> inside containing something like this:
>> <?xml version="1.0" encoding="UTF-8"?>
>> <!DOCTYPE application PUBLIC "-//Sun Microsystems, Inc.//DTD
>> J2EE Application 1.3//EN"
>> "http://java.sun.com/dtd/application_1_3.dtd">
>> <application id="mon appli">
>> <display-name>Whatever name you want</display-name>
>>
>> <module>
>> <ejb>youEjbJar.jar</ejb>
>> </module>
>> <module>
>> <web>
>> <web-uri>yourFirstWar.war</web-uri>
>> <context-root>war1</context-root>
>> <web>
>> </module>
>> <module>
>> <web>
>> <web-uri>yourSecondWar.war</web-uri>
>> <context-root>war2</context-root>
>> <web>
>> </module>
>> <!-- in the lib dir, you can just put every possible
>> libraries you might need in common for the modules. -->
>> <library-directory>lib</library-directory>
>> </application>
>>
>> Note that the reference to the DTD I put will help you if
>> you use a modern IDE: you'll have autocompletion and
>> documentation when just entering < (in eclipse. <ad>I wrote
>> a small recap about useful dtd/xsd on my blog, french,
>> sorry:
>>
>> http://batmat.net/blog/post/2008/06/24/Quelques-declarations-XSD-ou-DTD-de-formats-XML-connus</ad>).
>>
>> HTH.
>>
>>
>> Cheers.
>>
>> 2008/10/1 Martin Renaud <pm.renaud_at_gmail.com
>> <mailto:pm.renaud_at_gmail.com>>
>>
>> It could be great!!!
>> but the real big question is HOW?? The only way I have
>> be able to make ejb module used by ONE war file is by
>> adding the ejb-jar package into the war package... and
>> of course the same ejb-jar package deployed on the
>> glassfish server!
>>
>> mart.
>>
>>
>> On Wed, Oct 1, 2008 at 1:56 PM, Baptiste MATHUS
>> <ml_at_batmat.net <mailto:ml_at_batmat.net>> wrote:
>>
>> Eumm, I think this is already possible. One possible
>> way is to deploy an ear containing the corresponding
>> modules. Say a ejb module that'd be used by the two
>> war ones.
>>
>> I guess deploying them separately (outside an ear)
>> could also work, but I didn't tested it. But then
>> you would have to watch out the order in which
>> you're deploying your artifacts.
>>
>> Cheers.
>>
>> 2008/10/1 Martin Renaud <pm.renaud_at_gmail.com
>> <mailto:pm.renaud_at_gmail.com>>
>>
>> And would it possible to NOT include the ejb jar
>> into the war package. But only get a reference
>> to that ejb jar... to allow multiple war to
>> invoke the same ejb jar? and not include the
>> same ejb jar into each package of war?
>>
>> thks
>>
>> Martin
>>
>>
>> On Wed, Oct 1, 2008 at 1:05 PM, Eve Pokua
>> <gorgeous65_at_msn.com <mailto:gorgeous65_at_msn.com>>
>> wrote:
>>
>>
>> Kenneth,
>> Great to
>> know. Does this also mean that EB
>> would be package within Application client
>> as well as Web packages?
>> eve
>>
>>
>>
>>
>>
>> ------------------------------------------------------------------------
>>
>> Date: Wed, 1 Oct 2008 12:08:42 -0400
>> From: Kenneth.Saks_at_Sun.COM
>>
>> To: ejb_at_glassfish.dev.java.net
>> <mailto:ejb_at_glassfish.dev.java.net>
>> Subject: Re: war not see ejb jar...
>>
>>
>>
>> On Sep 30, 2008, at 2:05 PM, Martin Renaud
>> wrote:
>>
>> Hi,
>>
>> i really don't understand what you mean.
>> I've separated the client (.war) and
>> ejbs (ejb .jar). Java EE seems to be
>> very tricky...
>>
>>
>> Yes, many people feel that way about the the
>> requirement that EJB components be packaged
>> in their own ejb-jar. We're fixing it
>> in EJB 3.1 so that enterprise beans can be
>> packaged directly in a .war.
>>
>>
>> an example would be appreate. I joined a
>> zip file which contain the exercice.
>> This project have been created whit
>> MyEclipse.You're going to find 3
>> directories: BeanProject which englobe
>> the Web and the EJB. BeanProjectWeb
>> include JSP/servlet/etc and
>> BeanProjectEJB include ejb objects. Both
>> are deployed to a Glassfish server. In
>> debug mode, only directories are
>> deployed (directory BeanProjectWeb.war
>> and directory BeanProjectEJB.jar (these
>> are not file)). I whish to not create a
>> .ear file. Because eventually, other
>> .war files are going to use that
>> BeanProjectEJB.jar file.
>>
>>
>> I don't know the details of the support for
>> expanded directory deployment. If that's
>> the root of your problem I would suggest
>> posting to the glassfish forum :
>>
>> http://forums.java.net/jive/forum.jspa?forumID=56&start=0
>>
>> <http://forums.java.net/jive/forum.jspa?forumID=56&start=0>.
>>
>>
>>
>> thank.
>>
>> Martin Renaud
>>
>>
>>
>> On Tue, Sep 30, 2008 at 1:40 PM, Kenneth
>> Saks <Kenneth.Saks_at_sun.com
>> <mailto:Kenneth.Saks_at_sun.com>> wrote:
>>
>> Hi Martin,
>>
>> There are two typical ways this is
>> done. The first is simply to
>> repackage the interface within the
>> .war. The second is to refactor the
>> EJB client view classes and put them
>> in a .jar file that is placed within
>> a directory named "lib" at the
>> top-level of the .ear. Any .jars
>> in that directory are required to be
>> visible to all modules in the .ear.
>>
>>
>> On Sep 30, 2008, at 1:34 PM, Martin
>> Renaud wrote:
>>
>> 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 deployed on the
>> server 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 2.x server.
>>
>>
>> ClientSessionRemote.java
>> *Code:*
>>
>> package com.imagem;
>>
>> import javax.ejb.Remote;
>>
>> @Remote
>> public interface
>> ClientSessionRemote {
>>
>> public java.lang.String
>> SayHello();
>>
>> }
>>
>>
>>
>> ClientSession.java
>> *Code:*
>>
>> package com.imagem;
>>
>> import javax.ejb.Stateful;
>>
>> @Stateful
>> public class ClientSession
>> implements
>> ClientSessionRemote {
>>
>> public String SayHello(){
>> String msg="Hello! I am
>> Session Bean";
>>
>> System.out.println(msg);
>> return msg;
>> }
>>
>> }
>>
>>
>>
>> Controller.java (servlet)
>> *Code:*
>>
>> public class Controller extends
>> HttpServlet {
>>
>> @EJB
>> private ClientSessionRemote
>> m_testClientSessionBean;
>>
>> ...some 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();
>>
>>
>>
>>
>> }
>>
>> ...some code...
>>
>> }
>>
>>
>>
>> What else do i need to do?? any
>> help would be appreciate!!!
>>
>> thks
>>
>> Martin Renaud
>>
>>
>>
>>
>>
>> --
>> Martin Renaud
>>
>>
>> <BeanProject.zip>---------------------------------------------------------------------
>>
>> To unsubscribe, e-mail:
>> ejb-unsubscribe_at_glassfish.dev.java.net
>>
>> <mailto:ejb-unsubscribe_at_glassfish.dev.java.net>
>> For additional commands, e-mail:
>> ejb-help_at_glassfish.dev.java.net
>> <mailto:ejb-help_at_glassfish.dev.java.net>
>>
>>
>>
>>
>> ------------------------------------------------------------------------
>> Try Facebook in Windows Live Messenger! Try
>> it Now!
>>
>> <http://clk.atdmt.com/UKM/go/111354030/direct/01/>
>>
>>
>>
>>
>> -- Martin Renaud
>>
>>
>>
>>
>> -- Baptiste <Batmat> MATHUS -
>> http://batmat.net
>> Sauvez un arbre,
>> Mangez un castor !
>>
>>
>>
>>
>> -- Martin Renaud
>>
>>
>>
>>
>> -- Baptiste <Batmat> MATHUS - http://batmat.net
>> Sauvez un arbre,
>> Mangez un castor !
>>
>>
>>
>>
>> -- Martin Renaud
>>
>>
>>
>>
>> -- Baptiste <Batmat> MATHUS - http://batmat.net
>> Sauvez un arbre,
>> Mangez un castor !
>>
>>
>>
>>
>> --
>> Martin Renaud
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ejb-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: ejb-help_at_glassfish.dev.java.net
>