• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

JBOSS - need help with my first ejb deployment and testing

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.naming:org.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
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you don't have the jbossall-client.jar in the client classpath. Which version of JBoss AS do you use?
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic