Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

EJB 2.0 in JBoss 2.4.4

0 views
Skip to first unread message

Peter Wu

unread,
Mar 8, 2002, 2:49:16 AM3/8/02
to
Greetings,

I'm studying EJB by reading the Mastering EJB2 available from
TheServerSide.com.

I followed the chapter in the book and created a Stateless
SessionBean. I put the jar into the deploy folder of jboss and notice
that the jar was loaded successfully by jboss.

My question is how to use the ejb in a java client application. What
should I set for the client app to make the following call work.


Properties props = System.getProperties();
Context ctx = new InitialContext(props);
Object obj = ctx.lookup("HelloHome");


The client application resides on the same computer as jboss. TIA!

Peter

Andreas Wollschlaeger

unread,
Mar 8, 2002, 5:35:00 PM3/8/02
to
Peter Wu wrote:

> Greetings,
>
> I'm studying EJB by reading the Mastering EJB2 available from
> TheServerSide.com.
>
> I followed the chapter in the book and created a Stateless
> SessionBean. I put the jar into the deploy folder of jboss and notice
> that the jar was loaded successfully by jboss.
>
> My question is how to use the ejb in a java client application. What
> should I set for the client app to make the following call work.
>
>
> Properties props = System.getProperties();
> Context ctx = new InitialContext(props);
> Object obj = ctx.lookup("HelloHome");

Hi,
here is a code snippet from a current project:

Properties p = System.getProperties();
p.setProperty("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
p.setProperty("java.naming.provider.url", "127.0.0.1:1099");
p.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");

try {
//
// Get JNDI context
//
mJNDIContext = new javax.naming.InitialContext(p);
//
// Find home object
//
Object foo = mJNDIContext.lookup("FoobarEntity");
FoobarEntityHomeHome = (FoobarEntityHome)PortableRemoteObject.narrow(
foo, FoobarEntityHome.class);
System.out.println(" OK - have home interface");
}
catch (Exception __e){
System.out.println(" ARRGHH caught exception: " +
__e.getClass().getName());
throw new Error(__e.toString());
}
}

HTH
Andreas


--
/toe/ff
el@/treu/
f/uss.
de//

Peter Wu

unread,
Mar 8, 2002, 8:26:05 PM3/8/02
to
"Andreas Wollschlaeger" <postm...@1.0.0.127.in-addr.arpa> wrote in message
news:a6becp$o1i$07$1...@news.t-online.com...

>
> Properties p = System.getProperties();
> p.setProperty("java.naming.factory.initial",
> "org.jnp.interfaces.NamingContextFactory");
> p.setProperty("java.naming.provider.url", "127.0.0.1:1099");
> p.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");
>
> try {
> //
> // Get JNDI context
> //
> mJNDIContext = new javax.naming.InitialContext(p);
> //
> // Find home object
> //
> Object foo = mJNDIContext.lookup("FoobarEntity");
> FoobarEntityHomeHome = (FoobarEntityHome)PortableRemoteObject.narrow(
> foo, FoobarEntityHome.class);
> System.out.println(" OK - have home interface");
> }
> catch (Exception __e){
> System.out.println(" ARRGHH caught exception: " +
> __e.getClass().getName());
> throw new Error(__e.toString());
> }
> }
>
> HTH
> Andreas
>

Thank you, Andreas.

I tried your code in my test project but got the following errors.

C:\JDK\bin\javaw.exe -classpath
C:\JDK\jre\lib\rt.jar;C:\J2EE\lib\j2ee.jar;C:\Documents and Settings\Peter
Wu\My Documents\My Projects\TestApp\bin examples.HelloClient
javax.naming.NoInitialContextException: Cannot instantiate class:
org.jnp.interfaces.NamingContextFactory. Root exception is
java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:195)
at
com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:45)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:652)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:246)
at javax.naming.InitialContext.init(InitialContext.java:222)
at javax.naming.InitialContext.<init>(InitialContext.java:198)
at examples.HelloClient.main(HelloClient.java:35)
Exception in thread "main" Process terminated with exit code 1


If I debug the code, the exception occurs at the following line:

mJNDIContext = new javax.naming.InitialContext(p);

What do I need to add to my client application so that it can be aware of
the existence of JBoss? Thanks again! :)


--
Peter Wu
pet...@sunguru.com


Michiel Konstapel

unread,
Mar 9, 2002, 3:20:17 PM3/9/02
to
"Peter Wu" <pet...@sunguru.com> wrote in message
news:a6bobk$csr9e$1...@ID-117651.news.dfncis.de...

> "Andreas Wollschlaeger" <postm...@1.0.0.127.in-addr.arpa> wrote in
message
> news:a6becp$o1i$07$1...@news.t-online.com...
> >
> > Properties p = System.getProperties();
> > p.setProperty("java.naming.factory.initial",
> > "org.jnp.interfaces.NamingContextFactory");
> > p.setProperty("java.naming.provider.url", "127.0.0.1:1099");
> > p.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");
> >
<snip>

> What do I need to add to my client application so that it can be aware of
> the existence of JBoss? Thanks again! :)

You need the JBoss client stuff on the classpath as well. The jars are in
the client subdir of your JBoss installation. You probably don't need all of
them. Either check the docs or keep adding jars until it works. The JNDI
stuff is in jnp-client.jar.
HTH,
Michiel


Peter Wu

unread,
Mar 9, 2002, 9:09:10 PM3/9/02
to
"Michiel Konstapel" <a...@me.nl> wrote in message
news:58ui8.27212$Fw2.8...@nlnews00.chello.com...

> "Peter Wu" <pet...@sunguru.com> wrote in message
> > What do I need to add to my client application so that it can be aware
of
> > the existence of JBoss? Thanks again! :)
>
> You need the JBoss client stuff on the classpath as well. The jars are in
> the client subdir of your JBoss installation. You probably don't need all
of
> them. Either check the docs or keep adding jars until it works. The JNDI
> stuff is in jnp-client.jar.
> HTH,
> Michiel
>
>

Thanks a lot, Michiel!

I added jboss-client.jar to the classpath and my test client application
works perfectly! :)


Peter


Michiel Konstapel

unread,
Mar 10, 2002, 12:23:42 AM3/10/02
to
> Thanks a lot, Michiel!
>
> I added jboss-client.jar to the classpath and my test client application
> works perfectly! :)

Cool :)


Jerome Moliere

unread,
Mar 13, 2002, 8:11:13 AM3/13/02
to

Peter Wu wrote:

you should read a config file (.properties) containing the URL for the JNDI server location (usually

port 1099 for Jboss)

these are the properties I'm using (richelieu is the name of the machine
where the App server is):
java.naming.provider.url=richelieu:1099
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory

Jerome


0 new messages