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

EJB Woes

2 views
Skip to first unread message

kevin wright

unread,
Jun 20, 2006, 2:45:32 PM6/20/06
to
Hi Guys

I'm trying to create a Simple EJB application based on Ed Romans Mastering EntepriseJava beans.

So far I have:


1. Downloaded and installed J2EE

2. Written an compiled The Remote interface, the local interface, the Home interface, the local home interface
and the bean itself.

3. Created the deployment description in xml.

4. jarred the deployment descriptor and class files into an ejb-jar file.

5. Deployed the jar file

6. Startup up the ejb server.

Now my problems start when I try to run some client code:

package examples;

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

public class HelloClient{

public static void main(String[] args) throws Exception{

System.out.println("start of program");
Properties props = System.getProperties();

Context ctx = new InitialContext(props);

Object obj = ctx.lookup("HelloHome");

HelloHome home = (HelloHome) javax.rmi.PortableRemoteObject.narrow(
obj, HelloHome.class);

Hello hello = home.create();


System.out.println( hello.hello() );


hello.remove();

}

}

Code compiles but when I try to run it like this:


java -classpath /home/kevin/SUNWappserver/lib/j2ee.jar:. examples.HelloClient

I Get:

start of program
Exception in thread "main" 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:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at examples.HelloClient.main(HelloClient.java:16)

Please can you tell me why the code doesn't run?


Kevin Wright.

Philip Reimer

unread,
Jun 21, 2006, 6:41:53 AM6/21/06
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

kevin wright schrieb:

The Exception says it all. You don't get an InitialContext, because
there is no "java.naming.factory.initial" specified in the Properties
you pass to "new InitialContext()".

I don't know what the appropriate values are for the Sun app server.
Maybe you can try just "new InitialContext()" without passing any props.
If that doesn't work you have to specify something like this:

Properties p = new Properties();
p.put("java.naming.factory.initial","<Sun App Server Factory_Class>");

I'm sure you can find the appropriate Factory for Sun app server
somewhere in the documentation.

HTH,
Philip
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32)

iD8DBQFEmSJxOnXHmEVwvcQRAk8vAJ9j0WaRCPhN8MrijmTl7Yfan386GgCgkRO8
jpX95D96pyb7+G+vroZ1u9I=
=vPIb
-----END PGP SIGNATURE-----

kevin wright

unread,
Jun 21, 2006, 9:32:32 AM6/21/06
to


Hi Philip,

Thanks for that. Unfortunately, the documentation that arrives with Suns APP Server is pretty much impenetrable. Although I did locate
code that claimed to call an EJB method. On compiling and running,
the code also produced a NoInitialContextException.

On Sun's site I managed to find a FAQ talking about
a factory context class called: com.sun.enterprise.naming.SerialInitContextFactory

This class however does not come with the Sun's APP Server.

I now believe that the APP Server provides no such context factory class and by implication does not in fact
provide a mechanism to run EJB methods. All very dissapointing :(


Anyway, thanks again for your help.

Kevin Wright.

Philip Reimer

unread,
Jun 21, 2006, 10:42:09 AM6/21/06
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

kevin wright schrieb:

[snip]


> Hi Philip,

Hi.

> Thanks for that. Unfortunately, the documentation that arrives with Suns APP Server is pretty much impenetrable. Although I did locate
> code that claimed to call an EJB method. On compiling and running,
> the code also produced a NoInitialContextException.

> On Sun's site I managed to find a FAQ talking about
> a factory context class called: com.sun.enterprise.naming.SerialInitContextFactory

That seems to be it.

> This class however does not come with the Sun's APP Server.

> I now believe that the APP Server provides no such context factory class and by implication does not in fact
> provide a mechanism to run EJB methods. All very dissapointing :(

As Suns App Server serves as some kind of reference implementation for
j2ee stuff, it would be pretty silly not to provide EJB support. ;)
However, I've seen it running EJBs and all the information you need is
in the appserver-rt.jar which comes in the servers lib folder.
As the documentation states, all you should need to do is add this jar
to your clients class path and call "new InitialContext()" without any
properties.

> Anyway, thanks again for your help.

> Kevin Wright.

Greetings,
Philip

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32)

iD8DBQFEmVrBOnXHmEVwvcQRAsxHAJ9co73Gq4Lp300DD95TGn5bjNbHwgCdHHxf
hJU4t3c0hRFK6mM1ztweXhU=
=wNAv
-----END PGP SIGNATURE-----

kevin wright

unread,
Jun 21, 2006, 2:10:30 PM6/21/06
to

Hi Philip,

Including appserv-rt.jar in my classpath proved to be the turning point
after fixing a few minor errors in the code. I have now made
my first successful call to an ejb method. Time for a drink I think!

Thanks for that vital info.

Kevin Wright.

Philip Reimer

unread,
Jun 22, 2006, 3:43:56 AM6/22/06
to

> Hi Philip,

> Including appserv-rt.jar in my classpath proved to be the turning point
> after fixing a few minor errors in the code. I have now made
> my first successful call to an ejb method. Time for a drink I think!

Cheers.

> Thanks for that vital info.

> Kevin Wright.


Philip
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32)

iD8DBQFEmko8OnXHmEVwvcQRAv1+AJ9BPwKm2oqQyVizRTulW1b5P9zYkwCdGrUL
kufDn/fNjIcNPEHbnlW6snI=
=lycs
-----END PGP SIGNATURE-----

0 new messages