Win a copy of Spark in Action this week in the Open Source Projects forum!

Loukas G

Greenhorn
+ Follow
since Mar 04, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Loukas G

ok......... there is an error in the command to run the client. Instead of :
java -classpath %CLASSPATH%;%CLASSPATH%;\AdviceAppClient.jar AdviceClient
USE THIS :
java -classpath %CLASSPATH%;%CLASSPATH%\AdviceAppClient.jar AdviceClient
oh and not to forget...if you have any program running like Norton Internet Security you should disable it because it prevents the client to run and a bunch of exceptions appear from nowhere
Hello guys.
If you have an environment like mine and you were stuck for days
with trying to run the client......... i found the solution!
Windows XP
1.3.1 jdk2ee
j2sdk 1.4.2_03
The solution has to do with how you configure the CLASSPATH and what is the command to compile and run the client.
The source is as in the HF EJB book but instead of getAvice() i use getMessage() which i do not know if it helps!( I will test it with getAdvice() later) I also have added some comments for debugging purposes. Take a look:
-----------------------------CODE-----------------------------------------
import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;
import headfirst.*;
import javax.ejb.*;

public class AdviceClient
{
public static void main(String[] args)
{
new AdviceClient().go();
}
public void go() {
try
{
Context ic = new InitialContext();
System.out.println("Context Created!!!");
Object o = ic.lookup("Advisor");
System.out.println("Lookup DONE!!!");
AdviceHome home = (AdviceHome)PortableRemoteObject.narrow(o, AdviceHome.class);
System.out.println("Narrowing DONE!!!");
Advice advisor = home.create();
System.out.println("Remote Object Created!!!");
System.out.println(advisor.getMessage());
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}
----------------------------------------------------------------------------
---------------------SOLUTION-----------------------------------------------
1)Your CLASSPATH environmental variable should include the path to j2ee.jar and also to the advice directory like this:
C:\j2sdkee1.3.1\lib\j2ee.jar;C:\source\projects\advice
2)To compile the client you type the following from advice directory:
javac -classpath %CLASSPATH%;%CLASSPATH%\AdviceAppClient.jar AdviceClient.java
3)To run the client you type the following from advice directory:
java -classpath %CLASSPATH%;%CLASSPATH%;\AdviceAppClient.jar AdviceClient
That's all folks. I hope that will help you.
Ooh i can't stop running the client.....everytime a different message is displayed............he he
Hi, I am new at EJB and i read Head First EJB.I use Windows XP,J2EE Reference Implementation and J2SDK 1.4.2.When i tried to run the first example and specifically the client (AdviceClient) the following message was displayed:
E:\source\projects\advice>java AdviceClient
Context Created!!!
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(NamingManager.java:6
40)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243
)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.jav
a:280)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at AdviceClient.go(AdviceClient.java:21)
at AdviceClient.main(AdviceClient.java:12)

---------------------------CODE---------------------------------------------
import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;
import headfirst.*;
import javax.ejb.*;

public class AdviceClient
{
public static void main(String[] args)
{
new AdviceClient().go();
}
public void go() {
try
{
Context ic = new InitialContext();
System.out.println("Context Created!!!");
Object o = ic.lookup("Advisor");
System.out.println("Lookup DONE!!!");
AdviceHome home = (AdviceHome) PortableRemoteObject.narrow(o, AdviceHome.class);
System.out.println("Narrowing DONE!!!");
Advice advisor = home.create();
System.out.println("Remote Object Created!!!");
System.out.println(advisor.getAdvice());
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}

----------------------------------------------------------------------------
Now from the message i think that somewhere i must specify the properties of InitialContext.Am i right and if i am where and how can i do this? Kathy,Bert HELP please!
Hi, I am new at EJB and i read Head First EJB.I use Windows XP,J2EE Reference Implementation and J2SDK 1.4.2.When i tried to run the first example and specifically the client (AdviceClient) the following message was displayed:
E:\source\projects\advice>java AdviceClient
Context Created!!!
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(NamingManager.java:6
40)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243
)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.jav
a:280)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at AdviceClient.go(AdviceClient.java:21)
at AdviceClient.main(AdviceClient.java:12)

---------------------------CODE---------------------------------------------
import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;
import headfirst.*;
import javax.ejb.*;

public class AdviceClient
{
public static void main(String[] args)
{
new AdviceClient().go();
}
public void go() {
try
{
Context ic = new InitialContext();
System.out.println("Context Created!!!");
Object o = ic.lookup("Advisor");
System.out.println("Lookup DONE!!!");
AdviceHome home = (AdviceHome) PortableRemoteObject.narrow(o, AdviceHome.class);
System.out.println("Narrowing DONE!!!");
Advice advisor = home.create();
System.out.println("Remote Object Created!!!");
System.out.println(advisor.getAdvice());
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}

----------------------------------------------------------------------------
Now from the message i think that somewhere i must specify the properties of InitialContext.Am i right and if i am where and how can i do this? Kathy,Bert HELP please!
Please, ignore the first line of the error message.
Thank you.
The AdviceClient is compiled but not executed.Everything is executed according to the Head First EJb book's first example.Windows XP - J2EE 1.3.1 RI - J2SDK 1.4.2_03 are used.When i try to run AdviceClient :
java -classpath E:\j2sdkee1.3.1\lib\j2ee.jar;E:\source\projects\advice\AdviceAppClient.jar AdviceClient
The following error is provided which is very strange:
javac -classpath E:\j2sdkee1.3.1
Exception in thread "main" java.lang.NoClassDefFoundError: AdviceClient
Here is the code:
import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;
import headfirst.*;
import javax.ejb.*;

public class AdviceClient
{
public static void main(String[] args)
{
new AdviceClient().go();
}
public void go() {
try
{
Context ic = new InitialContext();
Object o = ic.lookup("Advisor");
AdviceHome home = (AdviceHome) PortableRemoteObject.narrow(o, AdviceHome.class);
Advice advisor = home.create();
System.out.println(advisor.getAdvice());
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}
Anyone who knows please tell me if i do something wrong or there is a bug in the RI.Thank you in advance