File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes I didn't run my client Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "I didn Watch "I didn New topic
Author

I didn't run my client

Carlos Rincon
Greenhorn

Joined: Mar 28, 2005
Posts: 22
Hello Everyone, I am using the Sun's RI (J2EE1.4 y Sun Java System Application Server Platform Edition 8 update 1), I created one cliente to access my EJB.

a)When I run my EJB client in this way:
java -cp .;adviceEarClient.jar AdviceClient1
where AdviceClient1 is the client class and adviceEarClient.jar containts stubs for the client.
I recive an error like:
--------------------------
javax.naming.NoInitialContextException: Need to specify class name in environmen
t or system property, or as an applet parameter, or in an application resource f
ile: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.lookup(Unknown Source)
at AdviceClient1.main(AdviceClient1.java:13)
---------------------------------------------------
b)But when I run it in this way (using appclient):
appclient -client adviceEarClient.jar
it work.

c)Here is my code:
Context initial = new InitialContext();
Object o = initial.lookup("MyAdviceBean"); // <--- here is the error
AdviceHome h =(AdviceHome)PortableRemoteObject.narrow(o, AdviceHome.class);
Advice adv = home.create();

My questions are:
1) Why
java -cp .;adviceEarClient.jar AdviceClient1
dont't work, but
appclient -client adviceEarClient.jar
does?

2) I saw some book use a property o hashtable to create the initial context, something like
Hashtable props = new Hashtable();
props.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
props.put(Context.PROVIDER_URL, "t3://weblogic:7001");
props.put(Context.SECURITY_PRINCIPAL, "fred");
props.put(Context.SECURITY_CREDENTIALS, "seafood");
Context initial = new InitialContext(props);

what are the values for Context.INITIAL_CONTEXT_FACTORY and Context.PROVIDER_URL in the case of the Sun Java System Application Server Platform Edition 8 update 1??
Marco Barenkamp
Ranch Hand

Joined: Aug 27, 2001
Posts: 94
Hi,

you need to specifiy how the jndi context should establish a connection.
Search for jndi.properties in the samples, e.g. and copy it into your CLASSPATH.
[ September 07, 2005: Message edited by: Marco Barenkamp ]

Marco Barenkamp<br />_ _ _ _ _ ________________________ _ _ _ _ _ <br />L M I N T E R N E T S E R V I C E S AG<br /> <br />Head of Software Development<br /> <br /> <br />BEA Certified Enterprise Developer<br />Sun Certified Programmer for the Java2 Platform<br />Sun Certified Web Component Developer for the Java2 Platform<br />Sun Certified Developer for the Java 2 Platform <br />Sun Certified Business Component Developer for the Java 2 Platform <br />Sun Certified Enterprise Architect for the Java 2 Platform Enterprise Edition<br /> <br />LMIS AG
Carlos Rincon
Greenhorn

Joined: Mar 28, 2005
Posts: 22
Thanks for repley, but the Sun Java System Application Platform's samples dont't come with
jndi.properties, either the j2eetutorial samples...
What about my 3 questions?...
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi Carlos,


1) Why
java -cp .;adviceEarClient.jar AdviceClient1
dont't work, but
appclient -client adviceEarClient.jar
does?

As a rule of thumb the INITIAL_CONTEXT_FACTORY and the PROVIDER_URL system properties must be defined within the environment your client code runs. The reason why your code works with the appclient is because the client container sets those properties for you. For the same very reason the same client code will work if it is deployed within a jsp or servlet (the server will initialize the environment when it starts). A local client on the other hand needs to initialize the environment using a code similar to that you�ve posted.

2) I saw some book use a property o hashtable to create the initial context, something like
Hashtable props = new Hashtable();
props.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
props.put(Context.PROVIDER_URL, "t3://weblogic:7001");
props.put(Context.SECURITY_PRINCIPAL, "fred");
props.put(Context.SECURITY_CREDENTIALS, "seafood");
Context initial = new InitialContext(props);

what are the values for Context.INITIAL_CONTEXT_FACTORY and Context.PROVIDER_URL in the case of the Sun Java System Application Server Platform Edition 8 update 1??

I�ve never used the Sun Java System Application Server and I cannot tell you what those properties are. There is however a very easy way to find out. Modify your AdviceClient1 to print those variable just after running main():

As for the other two properties you shouldn�t bother too much. They are required only when your ejbs are jndi-protected. However this is not a good practice and j2ee recommends using JAAS. Usually anonymous binding to the jndi should always work. You can always use the System class and print all the environment variables your client container sets if you�d like to make sure whether any jndi credentials should be set.
Regards.


I think, therefore I exist -- Rene Descartes
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I didn't run my client