EJB Woes

K

kevin wright

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.
 
P

Philip Reimer

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

kevin said:
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.

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-----
 
K

kevin wright

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

kevin said:
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.

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-----


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.
 
P

Philip Reimer

-----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-----
 
K

kevin wright

-----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-----

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.
 
P

Philip Reimer

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

kevin said:
On Wed, 21 Jun 2006 16:42:09 +0200, Philip Reimer wrote:

kevin wright schrieb:

[snip]

That seems to be it.
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.
Greetings,
Philip

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-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top