Forums Register Login

Error running AdviceClient

+Pie Number of slices to send: Send
On page 58, when I run AdviceClient it's giving me following error:
Exception in thread "main" java.lang.NoClassDefFoundError: AdviceClient
and till this last step, everything was just fine.
???
+Pie Number of slices to send: Send
Howdy Sean,
You're having a plain old Java problem at the moment... the JVM can't find your AdviceClient, so be CERTAIN that you're in the right directory, etc. And once again verify that your command-line looks like this:
java -cp {$CLASSPATH}:AdviceAppClient.jar AdviceClient
(allowing for the difference in syntax for your particular shell, of course)
Be certain that the -cp APPENDS to the current classpath, rather than changes it. And are you absolutely certain that your classpath includes the *current* directory (i.e. the '.') (it probably does if you made it this far).
Remember, the AdviceClient is NOT in a package, so you should simply compile it and run it from the very same directory. So verify again that your class is really in your current working directory that you cd'd to.
When I run this, I cd into the /advice directory; the same way I did to compile the client.
I'm thinking that it has to be something wrong either with your current working directory, OR that your current directory isn't on the classpath somehow.
You might want to give us some more details. Isn't it actually a little fun getting this *&%$# thing to work?
My favorite thought: It takes about 5 minutes to write a simple EJB, maybe 10 if you include the client, and about two days to get it deployed.
The good news is, once you do get it up and running, as long as you don't touch anything, ever again, on your computer, it should still work. Unless maybe one of those pesky neutrinos comes slamming into your JVM. And there's always a little Heisenberg uncertainty too... and let's not forget entropy... gosh, I'm getting depressed now just thinking about it. Quantum physics can really SUCK sometimes
OK, sorry. I've snapped out of it
Keep us posted. You WILL get this to work Sean! You're almost there... thanks for being persistent.
cheers,
Kathy
[see you all tomorrow... it's bedtime in Boulder]
+Pie Number of slices to send: Send
I solved CLASSPATH problem, but now I get this error:
javax.naming.CommunicationException: Can't find SerialContextProvider
???
Sean
+Pie Number of slices to send: Send
OK, now I've completely forgotten what system you are on... this doesn't sound like J2EE 1.3.1... or else there's still a classpath issue or... hmmm... can you please verify your system details again? And maybe paste in the stack trace here.
Thanks!
-Kathy
+Pie Number of slices to send: Send
I 'll write down two different senario:
First Senario: (Considernig I have set the CLASSPATH to E:\j2sdkee1.3.1E:\j2sdkee1.3.1\lib\j2ee.jar;
D:\Java\Head First EJB Projects\projects\advice\AdviceAppClient.jar;
D:\Java\Head First EJB Projects\projects\advice
through Windows Environment Variables):
and then:
D:\Java\Head First EJB Projects\projects\advice>java AdviceClient
javax.naming.CommunicationException: Can't find SerialContextProvider
at com.sun.enterprise.naming.SerialContext.getProvider(SerialContext.jav
a:63)
at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:120
)
at javax.naming.InitialContext.lookup(Unknown Source)
at AdviceClient.go(AdviceClient.java:20)
at AdviceClient.main(AdviceClient.java:12)
Second Senario: (Setting CLASSPATH at runtime in COMMAND PROMPT)
and then:
D:\Java\Head First EJB Projects\projects\advice>java -cp d:\java\head first ejb
projects\projects\advice:AdviceAppClient.jar AdviceClient
Exception in thread "main" java.lang.NoClassDefFoundError: first
j2sdee1.3.1 and j2sdk1.3.1 and Win 2000
Thank you very much in advance
Sean
+Pie Number of slices to send: Send
 

Originally posted by Sean Mohseni:
I 'll write down two different senario:
First Senario: (Considernig I have set the CLASSPATH to E:\j2sdkee1.3.1E:\j2sdkee1.3.1\lib\j2ee.jar;
D:\Java\Head First EJB Projects\projects\advice\AdviceAppClient.jar;
D:\Java\Head First EJB Projects\projects\advice
through Windows Environment Variables):
and then:
D:\Java\Head First EJB Projects\projects\advice>java AdviceClient
javax.naming.CommunicationException: Can't find SerialContextProvider
at com.sun.enterprise.naming.SerialContext.getProvider(SerialContext.jav
a:63)
at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:120
)
at javax.naming.InitialContext.lookup(Unknown Source)
at AdviceClient.go(AdviceClient.java:20)
at AdviceClient.main(AdviceClient.java:12)
Second Senario: (Setting CLASSPATH at runtime in COMMAND PROMPT)
and then:
D:\Java\Head First EJB Projects\projects\advice>java -cp d:\java\head first ejb
projects\projects\advice:AdviceAppClient.jar AdviceClient
Exception in thread "main" java.lang.NoClassDefFoundError: first
j2sdee1.3.1 and j2sdk1.3.1 and Win 2000
Thank you very much in advance
Sean


For the 2nd scenario, the no class found exception is thrown because you don't have currently directory in your classpath (I assume you are running in your currently directory:
D:\Java\Head First EJB Projects\projects\advice>java -cp "d:\java\head first ejb
projects\projects\advice";AdviceAppClient.jar;. AdviceClient
the period at the end means include current directory. Try this, I think you need to include j2ee.jar as well.
+Pie Number of slices to send: Send
Yes I,m running in the directory and i'm not sure about usnig "" that you had but after modifiying to:
D:\Java\Head First EJB Projects\projects\advice>java -cp d:\java\head first ejb
projects\projects\advice\AdviceAppClient.jar;. adviceClient
Exception in thread "main" java.lang.NoClassDefFoundError: first
So ???
Sean
+Pie Number of slices to send: Send
Any Idea?
+Pie Number of slices to send: Send
You need "" around the directory added to your classpath as Edward suggested because the folder "head first ejb project" has spaces in it's name.
With the way you are running things now, D:\java\head is added as the classpath and "first" is the class you are trying to run. Hence, the error.
+Pie Number of slices to send: Send
I have done the same but look at the result:
D:\Java\Head First EJB Projects\projects\advice>java -cp "d:\java\head first ejb
projects\projects\advice";AdviceAppClient.jar;. AdviceClient
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 AdviceClient.go(AdviceClient.java:20)
at AdviceClient.main(AdviceClient.java:12)
???
Sean
+Pie Number of slices to send: Send
Looks like you have crossed one hurdle...

Take a look at the following posting:
https://coderanch.com/t/208885/java/java/any-soln-javax-naming-NoInitialContextException
+Pie Number of slices to send: Send
I have done this too:
D:\Java\Head First EJB Projects\projects\advice>java -cp "d:\java\head first ejb
projects\projects\advice";AdviceAppClient.jar;e:\JNDI\jndi.properties;. AdviceClient
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 AdviceClient.go(AdviceClient.java:20)
at AdviceClient.main(AdviceClient.java:12)
Still ???
Sean
+Pie Number of slices to send: Send
Hey Sean,
Here my 2 cents. Keep in mind I'm a newbie.
Try including your current classpath in the classpath like the following
D:\Java\Head First EJB Projects\projects\advice>java -cp %classpath%;"d:\java\head first ejb projects\projects\advice";AdviceAppClient.jar;e:\JNDI\jndi.properties;. AdviceClient
Good luck,
Keith Rosenfield
SCJP
SCWCD
+Pie Number of slices to send: Send
Hi Keith,
D:\Java\Head First EJB Projects\projects\advice>java -cp %classpath%;"d:\java\he
ad first ejb projects\projects\advice";AdviceAppClient.jar;e:\JNDI\jndi.properti
es;. AdviceClient
Exception in thread "main" java.lang.NoClassDefFoundError: First
Still...
Sean
+Pie Number of slices to send: Send
Hey Sean,
Try this.
D:\Java\Head First EJB Projects\projects\advice>java -cp "%classpath%;d:\java\he
ad first ejb projects\projects\advice;AdviceAppClient.jar;e:\JNDI\jndi.properti
es;." AdviceClient

Notice the placement of the quotes.
Good luck,
+Pie Number of slices to send: Send
Unfortunately:
D:\Java\Head First EJB Projects\projects\advice>java -cp "%classpath%;d:\java\head first ejb projects\projects\advice;AdviceAppClient.jar;e:\JNDI\jndi.propertie
s;." AdviceClient
javax.naming.CommunicationException: Can't find SerialContextProvider
at com.sun.enterprise.naming.SerialContext.getProvider(SerialContext.jav
a:63)
at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:120
)
at javax.naming.InitialContext.lookup(Unknown Source)
at AdviceClient.go(AdviceClient.java:20)
at AdviceClient.main(AdviceClient.java:12)

Sean
+Pie Number of slices to send: Send
Hey Sean,
Too bad that didn't work. Are you running j2ee successfully before trying to run AdviceClient?
+Pie Number of slices to send: Send
Yes, I do. That's how I made and deployed the bean.
Sean
+Pie Number of slices to send: Send
Hey Sean,
I would like to try running your code on my machine. If I can recreate the problem, maybe I can find a solution. Please e-mail the code to keithrfield@hotmail.com.
+Pie Number of slices to send: Send
Here is the code I used to get the AdviceClient to work:
import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;
import headfirst.*;
import javax.ejb.*;
import java.util.*;
public class AdviceClient
{
public static void main(String args[])
{
new AdviceClient().go();
}
public void go()
{
try
{
Hashtable map = new Hashtable();
map.put("java.naming.factory.initial", "com.sun.jndi.cosnaming.CNCtxFactory");
map.put("java.naming.provider.url", "iiop://localhost:1050");
Context ic = new InitialContext(map);
Object o = ic.lookup("Advisor");
AdviceHome adviceHome = (AdviceHome)
PortableRemoteObject.narrow(o, AdviceHome.class);

Advice advice = adviceHome.create();
System.out.println(advice.getTheMessage());
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}
Don't forget you'll need the AdviceAppClient.jar and j2ee.jar files in the classpath.
+Pie Number of slices to send: Send
Hey Sean,
Your problem apparently is in the way you are getting the InitialContext. It is possible that the properties you have put in the hashtable are incorrect. You may want to try using the no argument constructor to get the InitialContext instead. That is how I did it.
Good luck.
+Pie Number of slices to send: Send
Hi Keith,
I tried Ringo Code and didn't work and also I tried to Email you my code that is telling me the Email address is not correct. So Would you please check the Email address for me then I send the folder to you.
Thank you very much in advance,
Sean
+Pie Number of slices to send: Send
Hey Sean,
What is Ringo code? You can e-mail me by clicking on the mail icon by any one of my posts.
+Pie Number of slices to send: Send
Hi Keith,
Ringo was the name of the person that 4 row above, has some code as the solution that didnot work for me.
anyway I've sent you an Email.
Thanks,
Sean
+Pie Number of slices to send: Send
I have done some changes and now I get:
D:\Java\Head First EJB Projects\projects\advice>java -cp "%classpath%;d:\java\he
ad first ejb projects\advice;AdviceAppClient.jar;e:\JNDI\jndi.properties;." AdviceClient
javax.naming.NameNotFoundException: Adviser not found
<<no stack trace available>>
And when I try to compile Kathy's code that I have downloaded, I get:
D:\EJB Head First\Code jar\HFEJBCODE\advice>javac -cp "d:\ejb head first\code jar\hfejbcode\advice\AdviceAppClient.jar" AdviceClient.java
javac: invalid flag: -cp
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-O Optimize; may hinder debugging or enlarge class file
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are us
ed
-classpath <path> Specify where to find user class files
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-d <directory> Specify where to place generated class files
-encoding <encoding> Specify character encoding used by source files
-target <release> Generate class files for specific VM version
I don't know what the problem is with synthax but anyway I set the classpath through Environment variables in windows and I still get:
D:\EJB Head First\Code jar\HFEJBCODE\advice>javac AdviceClient.java
AdviceClient.java:28: cannot resolve symbol
symbol : method getMessage ()
location: interface headfirst.Advice
System.out.println(advisor.getMessage());
^
1 error
Any idea appreciated.
Sean
+Pie Number of slices to send: Send
Hey Sean,
I'm pretty sure I know why you are getting the following error

Originally posted by Sean Mohseni:

D:\Java\Head First EJB Projects\projects\advice>java -cp "%classpath%;d:\java\he
ad first ejb projects\advice;AdviceAppClient.jar;e:\JNDI\jndi.properties;." AdviceClient
javax.naming.NameNotFoundException: Adviser not found
<<no stack trace available>>



When you deployed your bean you probably name it advisor, with an o. The client is looking for a bean named adviser, with an e. Just change the client to look for advisor, recompile and run.
Good Luck,
+Pie Number of slices to send: Send
Hi Keith,
You were right and now my problem is the Corba problem that I think I know how to solve:
D:\Java\Head First EJB Projects\projects\advice>java -cp "%classpath%;d:\java\he
ad first ejb projects\advice;AdviceAppClient.jar;e:\JNDI\jndi.properties;." Advi
ceClient
java.rmi.RemoteException: CORBA BAD_OPERATION 0 No; nested exception is:
org.omg.CORBA.BAD_OPERATION: minor code: 0 completed: No
org.omg.CORBA.BAD_OPERATION: minor code: 0 completed: No
at java.lang.Class.newInstance0(Native Method)
at java.lang.Class.newInstance(Unknown Source)
at com.sun.corba.ee.internal.iiop.messages.ReplyMessage_1_2.getSystemExc
eption(ReplyMessage_1_2.java:93)
at com.sun.corba.ee.internal.iiop.ClientResponseImpl.getSystemException(
ClientResponseImpl.java:108)
at com.sun.corba.ee.internal.POA.GenericPOAClientSC.invoke(GenericPOACli
entSC.java:132)
at org.omg.CORBA.portable.ObjectImpl._invoke(Unknown Source)
at headfirst._Advice_Stub.getAdvice(Unknown Source)
at AdviceClient.go(AdviceClient.java:25)
at AdviceClient.main(AdviceClient.java:12)
but can you tell me about two other problem that I have with Kathy's Source code.
Thanks,
Sean
+Pie Number of slices to send: Send
Now that I changed my method names and reDeploy the application, it gives me the same error that it gives me when I run Kathy's downloaded code.
D:\Java\Head First EJB Projects\projects\advice>javac AdviceClient.java
AdviceClient.java:25: cannot resolve symbol
symbol : method getMessage ()
location: interface headfirst.Advice
System.out.println(advisor.getMessage());
^
1 error
Considering the classpath is set.
Thanks,
Sean
+Pie Number of slices to send: Send
Hey Sean,
What you might want to try is to undeploy the bean. Then get rid of any files created as the result of deploying such as any .ear files and AdviceAppClient.jar and anything else that wasn't a file that you were responsible for creating. Also get rid of the .class files. Then recompile the bean, home and component classes. Deploy the bean. Then recompile the client. This process will ensure that the file AdviceAppClient.jar has been updated properly with the new versions of the files.
Good luck,
+Pie Number of slices to send: Send
That' what exactly I've done, and as I said I get the same error at compile time for the files that I downloaded from HFEJB web site.
Thanks,
sean
+Pie Number of slices to send: Send
Finally I did it.
Thank you veru much for all your effort.
Sean
+Pie Number of slices to send: Send
Congratulations Sean!!!
CHEERS!
How'd you do it? I was very confident that my last post would do the trick.
+Pie Number of slices to send: Send
Hi Keith,
I think removing temp files was the key and clean up and undeployment was not enough.
Anyway, thank you very much for your efforts.
Sean
Run away! Run away! Here, take this tiny ad with you:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1351 times.
Similar Threads
error with EJB first example
Head First EJB, AdviceBean & that damned SerialContextProvider
CORBA bad operation error in RI
how to connect EJB without using runclient
Found solution to AdviceClient...Ha Ha
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 01:09:08.