Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2006

Tip: Looking for answers? Try searching our database.

EJB Woes

Thread view: 
kevin wright - 20 Jun 2006 19:45 GMT
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 - 21 Jun 2006 11:41 GMT
kevin wright schrieb:
> Hi Guys
>
[quoted text clipped - 64 lines]
>
> 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
kevin wright - 21 Jun 2006 14:32 GMT
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
[quoted text clipped - 92 lines]
> =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.
Philip Reimer - 21 Jun 2006 15:42 GMT
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
kevin wright - 21 Jun 2006 19:10 GMT
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
[quoted text clipped - 43 lines]
> =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.
Philip Reimer - 22 Jun 2006 08:43 GMT
kevin wright schrieb:

> kevin wright schrieb:
>
[quoted text clipped - 25 lines]
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.