Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JBoss User »

[JBoss-user] JBoss example problem - new to J2EE

Robert Gallas

2003-12-05

Replies:

Hi,

I`m new to J2EE. I installed JBoss and would like to run a console example
(source code of all classes provided below). I succesfuly compiled, packaged
and deployed on JBoss but when running HelloWorldClient from console I get
the following messages.

1. when looking up "java:comp/env/ejb/HelloWorld"
Exception: comp not bound

OR

2. when looking up ""ejb/HelloWorld"
java.lang.NoClassDefFoundError:
Lorg/jboss/tm/TransactionPropagationContextFactory;
    at java.lang.Class.getDeclaredFields0(Native Method)
    at java.lang.Class.privateGetDeclaredFields (Class.java:1514)
    at java.lang.Class.getDeclaredField (Class.java:1206)
    at
java.io.ObjectStreamClass.getDeclaredSUID (ObjectStreamClass.java:1474)
    at java.io.ObjectStreamClass.access$400(ObjectStreamClass.java:47)
    at java.io.ObjectStreamClass$3.run(ObjectStreamClass.java:335)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.io.ObjectStreamClass.<init>(ObjectStreamClass.java:333)
    at java.io.ObjectStreamClass.lookup (ObjectStreamClass.java:253)
    at
java.io.ObjectStreamClass.initNonProxy (ObjectStreamClass.java:453)
    at
java.io.ObjectInputStream.readNonProxyDesc (ObjectInputStream.java:1521)
    at
java.io.ObjectInputStream.readClassDesc (ObjectInputStream.java:1435)
    at
java.io.ObjectInputStream.readOrdinaryObject (ObjectInputStream.java:1626)
    at
java.io.ObjectInputStream.readObject0 (ObjectInputStream.java:1274)
    at java.io.ObjectInputStream.readObject (ObjectInputStream.java:324)
    at java.util.HashMap.readObject (HashMap.java:1006)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39
)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java:25)
    at java.lang.reflect.Method.invoke (Method.java:324)
    at
java.io.ObjectStreamClass.invokeReadObject (ObjectStreamClass.java:838)
    at
java.io.ObjectInputStream.readSerialData (ObjectInputStream.java:1746)
    at
java.io.ObjectInputStream.readOrdinaryObject (ObjectInputStream.java:1646)
    at
java.io.ObjectInputStream.readObject0 (ObjectInputStream.java:1274)
    at
java.io.ObjectInputStream.defaultReadFields (ObjectInputStream.java:1845)
    at
java.io.ObjectInputStream.readSerialData (ObjectInputStream.java:1769)
    at
java.io.ObjectInputStream.readOrdinaryObject (ObjectInputStream.java:1646)
    at
java.io.ObjectInputStream.readObject0 (ObjectInputStream.java:1274)
    at java.io.ObjectInputStream.readObject (ObjectInputStream.java:324)
    at
org.jboss.proxy.ClientContainer.readExternal (ClientContainer.java:112)
    at
java.io.ObjectInputStream.readExternalData (ObjectInputStream.java:1686)
    at
java.io.ObjectInputStream.readOrdinaryObject (ObjectInputStream.java:1644)
    at
java.io.ObjectInputStream.readObject0 (ObjectInputStream.java:1274)
    at
java.io.ObjectInputStream.defaultReadFields (ObjectInputStream.java:1845)
    at
java.io.ObjectInputStream.readSerialData (ObjectInputStream.java:1769)
    at
java.io.ObjectInputStream.readOrdinaryObject (ObjectInputStream.java:1646)
    at
java.io.ObjectInputStream.readObject0 (ObjectInputStream.java:1274)
    at java.io.ObjectInputStream.readObject (ObjectInputStream.java:324)
    at java.rmi.MarshalledObject.get (MarshalledObject.java:135)
    at
org.jnp.interfaces.MarshalledValuePair.get (MarshalledValuePair.java:30)
    at org.jnp.interfaces.NamingContext.lookup (NamingContext.java:550)
    at org.jnp.interfaces.NamingContext.lookup (NamingContext.java:507)
    at javax.naming.InitialContext.lookup (InitialContext.java:347)
    at
com.mastertech.sample.HelloWorldClient.main(HelloWorldClient.java:23)
Exception in thread "main"

When deploying JBoss says:
08:56:22,062 INFO [MainDeployer] Starting deployment of package:
file:/D:/JBoss/server/default/deploy/HelloApp.ear
08:56:22,078 INFO [EARDeployer] Init J2EE application:
file:/D:/JBoss/server/default/deploy/HelloApp.ear
08:56:22,718 INFO [EjbModule] Deploying HelloWorld
08:56:22,828 INFO [StatelessSessionInstancePool] Started
jboss.j2ee:jndiName=ejb/HelloWorld,plugin=pool,service=EJB
08:56:22,843 INFO [StatelessSessionContainer] Started
jboss.j2ee:jndiName=ejb/HelloWorld,service=EJB
08:56:22,843 INFO [EjbModule] Started
jboss.j2ee:module=HelloEJB.jar,service=EjbModule
08:56:22,843 INFO [EJBDeployer] Deployed:
file:/D:/JBoss/server/default/tmp/deploy/tmp43628HelloApp.ear-contents/Hello
EJB.jar
08:56:22,875 INFO [EARDeployer] Started J2EE application:
file:/D:/JBoss/server/default/deploy/HelloApp.ear
08:56:22,875 INFO [MainDeployer] Deployed package:
file:/D:/JBoss/server/default/deploy/HelloApp.ear


I do not uderstand this because in J2EE spec there is writen that when
deploing EJB it is deployed in the namespace "java:comp/env/ejb" and it
seems it is not there.

Questions:
1. could somebody explain me in what namespace look for the HelloWorld ejb
and why.
2. could somebody explain me how to make that example work and why it
doesn`t work now

Thanks a lot for help and sorry for long mail.

Regards Robert


>file: HelloWorld -----------------------------------------
package com.mastertech.sample;

public interface HelloWorld extends javax.ejb.EJBObject {
  public String hello() throws java.rmi.RemoteException;
}

>file: HelloWorldHome -------------------------------------
package com.mastertech.sample;

public interface HelloWorldHome extends javax.ejb.EJBHome {
  HelloWorld create() throws java.rmi.RemoteException,
javax.ejb.CreateException;
}

>file: HelloWorldBean -------------------------------------
package com.mastertech.sample;

import javax.ejb.SessionContext;

public class HelloWorldBean implements javax.ejb.SessionBean {
  private SessionContext ctx;

  public HelloWorldBean() {}
  public void ejbActivate() throws javax.ejb.EJBException,
java.rmi.RemoteException {}
  public void ejbCreate() throws javax.ejb.EJBException,
java.rmi.RemoteException {}
  public void ejbPassivate() throws javax.ejb.EJBException,
java.rmi.RemoteException {}
  public void ejbRemove() throws javax.ejb.EJBException,
java.rmi.RemoteException {}

  public void setSessionContext(javax.ejb.SessionContext ctx) {
    this.ctx = ctx;
  }

  public String hello() {
    System.out.println("hello()");
    return "Hello World!";
  }
}

>file: HelloWorldClient -----------------------------------
package com.mastertech.sample;

import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.*;

public class HelloWorldClient {

  public HelloWorldClient() {
  }

  public static void main(String[] args) {
    Hashtable env = new Hashtable();

    env.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
    env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
    env.put("java.naming.factory.url.pkgs",
"org.jboss.naming:org.jnp.interfaces");

    try {
       Context ctx = new InitialContext(env);

       System.out.println("1");
       Object obj = ctx.lookup("java:comp/env/ejb/HelloWorld");
       System.out.println("2");
       HelloWorldHome home =
(HelloWorldHome)javax.rmi.PortableRemoteObject.narrow(obj,
HelloWorldHome.class);
       HelloWorld helloWorld = home.create();

       System.out.println ( helloWorld.hello() );
       helloWorld.remove();
    } catch (Exception e) {
       //e.printStackTrace();
       System.out.println( "Exception: " + e.getMessage() );
    }
  }
}

>file: ejb-jar.xml ------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise
JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">

<ejb-jar>
  <description>JBoss Hello World Application</description>
  <display-name>Hello World EJB</display-name>
  <enterprise-beans>
    <session>
       <ejb-name>HelloWorld</ejb-name>
       <home>com.mastertech.sample.HelloWorldHome</home>
       <remote>com.mastertech.sample.HelloWorld</remote>
       <ejb-class>com.mastertech.sample.HelloWorldBean</ejb-class>
       <session-type>Stateless</session-type>
       <transaction-type>Bean</transaction-type>
    </session>
  </enterprise-beans>
</ejb-jar>

>file: application.xml -------------------------------------
<?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>
 <display-name>Sum Application</display-name>
 <module>
   <ejb>HelloEJB.jar</ejb>
 </module>
</application>

>file: jboss.xml -------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 3.2//EN"
"http://www.jboss.org/j2ee/dtd/jboss_3_2.dtd">

<jboss>
 <enterprise-beans>
   <session>
     <ejb-name>HelloWorld</ejb-name>
     <jndi-name>ejb/HelloWorld</jndi-name>
    <method-attributes>
    </method-attributes>
   </session>
 </enterprise-beans>
 <resource-managers>
 </resource-managers>
</jboss>


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.




-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills. Sign up for IBM's
Free Linux Tutorials. Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
_______________________________________________
JBoss-user mailing list
JBoss-user@(protected)
https://lists.sourceforge.net/lists/listinfo/jboss-user


©2008 junlu.com - Jax Systems, LLC, U.S.A.