@EJB and RMI stubs
Hi,
I have deployed an EJB 3.0 and an corresponding application client on sun application server 9. I deployed these two entities seperated from each other in their jar-files. This means I used no ear because I wanted to use the deployed ejb from various application clients.
Now if I use @EJB on my static bean interface variable I get the following error (snippet):
WARNUNG: ACC003: Application threw an exception.
javax.naming.NamingException: ejb ref resolution error for remote business inter
faceejb.SimpleStatelessBean [Root exception is java.lang.ClassNotFoundException:
ejb.SimpleStatelessBean]
...
If I choose "RMIStubs" when I deploy my application client JAR file 韙 works.
If I use:
InitialContext ic =new InitialContext();
SimpleStatelessBean ssb = (SimpleStatelessBean) ic.lookup("ejb.SimpleStatelessBean");
instead of:
@EJB
privatestatic SimpleStatelessBean ssb;
it works with and without rmi stubs.
So what's the problem here?
I really would appreciate any hints or help because I have benn trying to figure this out on myself for the 2 days without any luck.
Thanks in advance.
Walter
Has nobody an hint what I am understanding wrong here?Any help would be greatly appreciated.Thanks.Walter
Hi Walter,Sounds like a packaging issue. You shouldn't need to use the static RMI-IIOP stub option. Is the EJB 3.0 Remote business interface packaged in your application client module? --ken
ksaksa at 2007-7-14 22:44:03 >

Hi.
Thanks for you reply.
I made about 50 attempts. Sometimes with business interface in my application client jar and sometimes without. It never worked without stubs. It is driving me insane...
Could you outline an appropriate application client structure sample (only which file belongs where)?
Can I simply put my EJB 3.0 Remote business interface as jar file in the root of my application client jar file? Or do I have to embed the interfaces directly as files?
Walter
> Could you outline an appropriate application client
> structure sample (only which file belongs where)?
If there's an application-client.xml it's in META-INF, but that's
typically not needed for Java EE 5 when you're using
annotations. All other classes are added directly to the
.jar, including the remote business interfaces and any
classes they refer to.
>
> Can I simply put my EJB 3.0 Remote business interface
> as jar file in the root of my application client jar
> file?
No.
>Or do I have to embed the interfaces directly
> as files?
Yes, add them to the jar according to their package. E.g.
foo.Bar would be in foo/Bar.class
We have simple examples here:
https://glassfish.dev.java.net/javaee5/ejb/EJB30.html
>
> Walter
ksaksa at 2007-7-14 22:44:03 >

Thanks again.
My source code is nearly identical to the samples at https://glassfish.dev.java.net/javaee5/ejb/EJB30.html. But I can't get it to work.
if I use:
InitialContext ic = new InitialContext();
ssb = (SimpleStatelessBean) ic.lookup("ejb.SimpleStatelessBean");
Item it = ssb.getItem(new Long(45));
everything is working fine. But if i use
@EJB
private static SimpleStatelessBean ssb; // global
Item it = ssb.getItem(new Long(45)); // within main
I always get a NullPointerException.
If I add a test statement to ensure ssb is not null, I always find out that ssb is null:
// within main
if (ssb == null)
System.out.println("null reference");
I added the remote business interface directly to my application client jar like you suggested. But it seems if i use @EJB, my corresponding variable ssb gets never initialized.
Any further ideas what I am doing wrong?
Are you invoking the client using the appclient command?
ksaksa at 2007-7-14 22:44:03 >

Yes. I useappclient -client <downloadedClientStub>
OK, can you post the contents of the downloaded client .jar file. Do a "jar tvf" and post the output, and also post the text of any application-client.xml or sun-application-client.xml in there, including in any embedded .jars. Thanks. --ken
ksaksa at 2007-7-14 22:44:03 >

I have recreated my projects with the Sless sample code - still with the same problem. Here is the requested code. Thanks for your efforts!
Output of jar tvf SlessApp.jar:
381 Thu Sep 14 17:58:06 CEST 2006 META-INF/application-client.xml
374 Thu Sep 14 17:58:06 CEST 2006 META-INF/sun-application-client.xml
197 Thu Sep 14 17:58:06 CEST 2006 ejb30/Sless.class
927 Thu Sep 14 17:58:06 CEST 2006 ejb30/SlessAppClient.class
59 Thu Sep 14 17:58:06 CEST 2006 META-INF/MANIFEST.MF
Content of application-client.xml
<?xml version="1.0" encoding="UTF-8"?>
<application-client xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
metadata-complete="true" version="5"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application-client_5.xsd">
<display-name>
SlessApp</display-name>
</application-client>
Content of sun-application.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sun-application-client PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Application Client 5.0//EN" "http://www.sun.com/software/appserver/dtds/sun-application-client_5_0-0.dtd">
<sun-application-client>
<java-web-start-access>
<eligible>true</eligible>
</java-web-start-access>
</sun-application-client>
Content of manifest.mf
Manifest-Version: 1.0
Main-Class: ejb30.SlessAppClient
Content of SlessAppClient.java
package ejb30;
import javax.ejb.EJB;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class SlessAppClient {
@EJB
private static Sless sless;
public static void main(String args[]) throws NamingException {
//It works by uncommenting the following lines!
//InitialContext ic = new InitialContext();
//sless = (Sless) ic.lookup("ejb30.Sless");
System.out.println("Sless bean says : " + sless.hello());
}
}
Content of Sless.java (Remote Business Interface)
package ejb30;
import javax.ejb.Remote;
@Remote
public interface Sless {
public String hello();
}
Does your original application client.jar have an application-client.xml file?If so, please post it. It lookslike your annotations are not being processed. One reason would be if the original application client .jar had an application-client.xml file with metadata-complete="true".
ksaksa at 2007-7-14 22:44:03 >

You were right. My original application client jar file contains a metadata-complete="true".
I work with Eclipse / WTP and WTP only supports EJB up to 2.1. So I copied the basic config file content from a NetBeans sample app. I never had thought that the problem could originate from the deployment descriptor. I was looking for the cause of the problem for some days now.
Thank you very very very much!
Glad to help :-)Thanks for using the Java EE SDK. --ken
ksaksa at 2007-7-14 22:44:03 >
