Hi all,
I'm am learning EJBs from Richard Monson-Haefel's Enterprise
JavaBeans.
I am doing the example from chapter 4 which has one entity bean and
one session bean which are deployed as separate jar files.
The entity bean seems to work fine when accessed from a client program
but when I try and look it up from the session bean I get the error:
javax.naming.CommunicationException. Root exception is
java.lang.ClassNotFoundException: com.titan.cabin.CabinHome
[TravelAgentBean] at java.lang.Throwable.<init>(Throwable.java:96)
[TravelAgentBean] at java.lang.Exception.<init>(Exception.java:44)
[TravelAgentBean] at
java.lang.ClassNotFoundException.<init>(ClassNotFoundException.java:71)
[TravelAgentBean] at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
[TravelAgentBean] at java.lang.ClassLoader.loadClass(ClassLoader.java(Compiled
Code))
[TravelAgentBean] at java.lang.ClassLoader.loadClass(ClassLoader.java:257)
[TravelAgentBean] at java.lang.Class.forName0(Native Method)
[TravelAgentBean] at java.lang.Class.forName(Class.java:212)
[TravelAgentBean] at
sun.rmi.server.MarshalInputStream.resolveProxyClass(MarshalInputStream.java:206)
[TravelAgentBean] at
java.io.ObjectInputStream.inputProxyClassDescriptor(ObjectInputStream.java:988)
[TravelAgentBean] at
java.io.ObjectInputStream.readObject(ObjectInputStream.java:376)
[TravelAgentBean] at
java.io.ObjectInputStream.readObject(ObjectInputStream.java:242)
[TravelAgentBean] at
java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1192)
[TravelAgentBean] at
java.io.ObjectInputStream.readObject(ObjectInputStream.java:392)
[TravelAgentBean] at
java.io.ObjectInputStream.readObject(ObjectInputStream.java:242)
[TravelAgentBean] at java.rmi.MarshalledObject.get(MarshalledObject.java:144)
[TravelAgentBean] at
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:299)
[TravelAgentBean] at
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:279)
[TravelAgentBean] at javax.naming.InitialContext.lookup(InitialContext.java:351)
[TravelAgentBean] at
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:367)
[TravelAgentBean] at
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:403)
[TravelAgentBean] at
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:279)
[TravelAgentBean] at javax.naming.InitialContext.lookup(InitialContext.java:351)
[TravelAgentBean] at
com.titan.travelagent.TravelAgentBean.listCabins(TravelAgentBean.java:21)
...
Here is the relevant code:
TravelAgentBean.java:
...
public String [] listCabins(int shipID, int bedCount) {
try {
javax.naming.Context jndiContext = new InitialContext();
Object obj = jndiContext.lookup("java:comp/env/ejb/Cabin");
CabinHome home = (CabinHome)
javax.rmi.PortableRemoteObject.narrow(obj, CabinHome.class);
...
private javax.naming.Context getInitialContext()
throws javax.naming.NamingException{
System.setProperty("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
System.setProperty("java.naming.provider.url",
"localhost:1099");
return new InitialContext();
}
...
ejb-jar.xml:
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>TravelAgentBean</ejb-name>
<home>com.titan.travelagent.TravelAgentHome</home>
<remote>com.titan.travelagent.TravelAgent</remote>
<ejb-class>com.titan.travelagent.TravelAgentBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<ejb-ref>
<ejb-ref-name>ejb/Cabin</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<home>com.titan.cabin.CabinHome</home>
<remote>com.titan.cabin.Cabin</remote>
</ejb-ref>
</session>
</enterprise-beans>
jboss.xml:
<jboss>
<secure>false</secure>
<container-configurations />
<resource-managers />
<enterprise-beans>
<session>
<ejb-name>TravelAgentBean</ejb-name>
<jndi-name>TravelAgent</jndi-name>
<configuration-name></configuration-name>
<ejb-ref>
<ejb-ref-name>ejb/Cabin</ejb-ref-name>
<jndi-name>Cabin</jndi-name>
</ejb-ref>
</session>
</enterprise-beans>
</jboss>
and from CabinBean:
tulip:/usr/local/jboss/deploy$ jar tvf cabin.jar
0 Sun Nov 19 09:19:22 GMT+13:00 2000 META-INF/
62 Sun Nov 19 09:19:22 GMT+13:00 2000 META-INF/MANIFEST.MF
479 Sun Nov 19 09:19:20 GMT+13:00 2000 com/titan/cabin/Cabin.class
1468 Sun Nov 19 09:19:20 GMT+13:00 2000 com/titan/cabin/CabinBean.class
395 Sun Nov 19 09:19:20 GMT+13:00 2000 com/titan/cabin/CabinHome.class
573 Sun Nov 19 09:19:20 GMT+13:00 2000 com/titan/cabin/CabinPK.class
1724 Sun Nov 19 09:19:22 GMT+13:00 2000 META-INF/ejb-jar.xml
2849 Sun Nov 19 09:19:22 GMT+13:00 2000 META-INF/jaws.xml
340 Sun Nov 19 09:19:22 GMT+13:00 2000 META-INF/jboss.xml
ejb-jar.xml:
<ejb-jar>
<enterprise-beans>
<entity>
<description>
This Cabin enterprise bean entity represents a cabin on
a cruise ship.
</description>
<ejb-name>Cabin</ejb-name>
<home>com.titan.cabin.CabinHome</home>
<remote>com.titan.cabin.Cabin</remote>
<ejb-class>com.titan.cabin.CabinBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>com.titan.cabin.CabinPK</prim-key-class>
<reentrant>False</reentrant>
<cmp-field><field-name>id</field-name></cmp-field>
<cmp-field><field-name>name</field-name></cmp-field>
<cmp-field><field-name>deckLevel</field-name></cmp-field>
<cmp-field><field-name>ship</field-name></cmp-field>
<cmp-field><field-name>bedCount</field-name></cmp-field>
</entity>
</enterprise-beans>
...
jboss.xml:
<jboss>
<secure>false</secure>
<container-configurations />
<resource-managers />
<enterprise-beans>
<entity>
<ejb-name>Cabin</ejb-name>
<jndi-name>Cabin</jndi-name>
<configuration-name></configuration-name>
</entity>
</enterprise-beans>
</jboss>
I'm and running this on Debian GNU/Linux x86 (woody) using
jboss2.0_FINAL:
[Info] Java version: 1.3.0,IBM Corporation
[Info] Java VM: Classic VM 1.3.0,IBM Corporation
[Info] System: Linux 2.2.13,x86
the complete cabin example (that I have edited) can be download from:
http://casquet.inet.net.nz/cabinejb.tar.gz
Thanks for your help.
--
Geoff Jacobsen. http://casquet.inet.net.nz/geoff
--
--------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Problems?: [EMAIL PROTECTED]