GeeCON Prague 2014*
The moose likes JBoss/WildFly and the fly likes JBOSS - need help with my first ejb deployment and testing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "JBOSS - need help with my first ejb deployment and testing" Watch "JBOSS - need help with my first ejb deployment and testing" New topic
Author

JBOSS - need help with my first ejb deployment and testing

Arnab Sinha
Ranch Hand

Joined: Jul 23, 2006
Posts: 72
Hi All,

I downloaded JBOSS 4.0.2 app server. I am doing the first program from HF EJB book.

I was able to compile the bean class and interfaces and package them into the jar file.

I believe I was also able to deploy it successfully because I can see my bean in the JMX console:

+- ejb (class: org.jnp.interfaces.NamingContext)
| +- AdviceBean (proxy: $Proxy50 implements interface headfirst.AdviceHome,interface javax.ejb.Handle)

However my problem is when I invoke the bean from a core java class:

import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;
import headfirst.*;
import javax.ejb.*;


public class AdviceClient
{
public static void main(String[] args)
{
new AdviceClient().go();
}

public void go() {
try
{
Context ic = new InitialContext();
Object o = ic.lookup("ejb/AdviceBean");

AdviceHome home = (AdviceHome) PortableRemoteObject.narrow(o, AdviceHome.class);

Advice advisor = home.create();
System.out.println(advisor.getAdvice());
}
catch (Exception ex)
{
ex.printStackTrace();
}

}
}

It compiles fine but when I try executing the client I get the following run-time error:

java AdviceClient

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:640)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:280)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at AdviceClient.go(AdviceClient.java:19)
at AdviceClient.main(AdviceClient.java:12)

ejb-jar.xml

<ejb-jar>

<display-name>EJB1</display-name>

<enterprise-beans>
<!-- Session Beans -->
<session>
<display-name>AdviceBean</display-name>
<ejb-name>AdviceBean</ejb-name>
<home>headfirst.AdviceHome</home>
<remote>headfirst.Advice</remote>
<ejb-class>headfirst.AdviceBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Bean</transaction-type>
</session>

</enterprise-beans>

</ejb-jar>

Any help would be appreciated.

Thanks in advance.
[ October 16, 2007: Message edited by: Arnab Sinha ]

SCJP 1.4: 91%<br />SCWCD 1.4: 85%
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10140
    
165

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial


Arnab,

You have to place a jndi.properties file in the classpath of the client application. The jndi.properties will contain the Context related information for the jndi lookup. For more details have a look at I get NoInitialContextException


[My Blog] [JavaRanch Journal]
tarun bhatt
Greenhorn

Joined: Jul 24, 2009
Posts: 1
Jaikiran Pai wrote:
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial


Arnab,

You have to place a jndi.properties file in the classpath of the client application. The jndi.properties will contain the Context related information for the jndi lookup. For more details have a look at I get NoInitialContextException



Hi i gt it
but an error is still dre the following is the error


{

Exception in thread "main" java.lang.NoClassDefFoundError: Ljavax/transaction/TransactionManager;
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Unknown Source)
at java.lang.Class.getDeclaredField(Unknown Source)
at java.io.ObjectStreamClass.getDeclaredSUID(Unknown Source)
at java.io.ObjectStreamClass.access$700(Unknown Source)
at java.io.ObjectStreamClass$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.io.ObjectStreamClass.<init>(Unknown Source)
at java.io.ObjectStreamClass.lookup(Unknown Source)
at java.io.ObjectStreamClass.initNonProxy(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at org.jboss.proxy.Interceptor.readExternal(Interceptor.java:80)
at java.io.ObjectInputStream.readExternalData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at org.jboss.proxy.Interceptor.readExternal(Interceptor.java:80)
at java.io.ObjectInputStream.readExternalData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at org.jboss.proxy.ClientContainer.readExternal(ClientContainer.java:157)
at java.io.ObjectInputStream.readExternalData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at java.rmi.MarshalledObject.get(Unknown Source)
at org.jnp.interfaces.MarshalledValuePair.get(MarshalledValuePair.java:72)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:655)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:590)
at javax.naming.InitialContext.lookup(Unknown Source)
at AdviceClient.go(AdviceClient.java:31)
at AdviceClient.main(AdviceClient.java:13)

}

my client looks like this

import javax.naming.*;
import javax.rmi.PortableRemoteObject;

import java.rmi.*;
import java.util.Properties;

import headfirst.*;
import javax.ejb.*;


public class AdviceClient {
public static void main(String args[]){
new AdviceClient().go();
}
public void go(){

try{
Properties properties = new Properties();

properties.put("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.factory.url.pkgs",
"org.jboss.namingrg.jnp.interfaces ");
properties.put("java.naming.provider.url",
"jnp://localhost:1099");


System.out.println("start");
Context ic = new InitialContext(properties);
System.out.println("exception in lookup");
Object o = ic.lookup("AdviceBean");
System.out.println("exception in portable remote object");
AdviceHome home = (AdviceHome)PortableRemoteObject.narrow(o,AdviceHome.class);
System.out.println("exception in home.create");
Advice advisor = home.create();
System.out.println((advisor.getAdvice()));
}
catch(Exception e){
e.printStackTrace();
System.out.println(e.getStackTrace());
}
}
}





I think dre is some problem at "Object o = ic.lookup("AdviceBean");" because sop's till dre are getting printed

Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10140
    
165

I guess you don't have the jbossall-client.jar in the client classpath. Which version of JBoss AS do you use?
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10140
    
165

Hmmm, did not realize it was a 2 year old post Tarun, henceforth if you have any questions please open a new thread instead of adding to old thread. That way, we don't mix multiple issues in a since thread. Thanks
 
GeeCON Prague 2014
 
subject: JBOSS - need help with my first ejb deployment and testing