Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!

Martin Brice

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

Recent posts by Martin Brice

I'm just about to try this out tonight. Thank you for the reply.
Thank you for the info. Ya, I found this out as well yesterday. I did the method name change and things worked, eventually. :< I had to play around quite a bit with the classpaths, directories, etc. :< But I did get it working eventually, so that's a good thing. :>
Thanks for the reply. :>
I got it to run, but this is the only command that I could get it to work with.
D:\Ejbs\advice>java -classpath .\;.\classes;d:\j2sdkee1.3.1\lib\j2ee.jar;.\AdviceAppClient.jar AdviceClient
It appears like I HAVE to put in the . the .\classes the j2ee.jar in addition to what's in the book on pg 57. MAN! That's nasty for a beginner to have to figure out on their own. :<
16 years ago
I'm trying to compile and then run the code for from page 57, and I'm getting the following error when I goto run the code.
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet pa
rameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(
at javax.naming.InitialContext.getDefaultInitCtx(
at javax.naming.InitialContext.getURLOrDefaultInitCtx(
at javax.naming.InitialContext.lookup(
at AdviceClient.go(
at AdviceClient.main(
I'm using the following two lines to compile and then run it.
D:\Ejbs\advice>javac -classpath .\classes;d:\j2sdkee1.3.1\lib\j2ee.jar
D:\Ejbs\advice>java AdviceClient
What is going on here?
First, I would like to say the Head First EJB book is entertaining while you read it. But I have to say, while doing the FIRST real exercise (Advice guy ejb), I have done exactly as the book has stated, but nothing very little works that way! The examples are assuming I'm using unix or linux, which 75% of the people reading this intro book I'm sure aren't, I always have to put on a -classpath d:\j2sdkee1.3.1\lib\j2ee.jar to every javac line, and I STILL get errors about not being able to import javax.ejb, and then there's errors with unable to find my main when I run the AdviceClient.
I enjoy reading the book, but the coding in the book is a bit frustrating. To make matters worse, after many hours of fighting with the code, I went to the errata site thinking this just wasn't right, and there is a "problem with the RI server", something about the getAdvice() call. I like how you are using the lowed common denominator to teach the essentials, but you have to ensure that denominator is working! The people reading your book are not able to just flip in a new ejb container like the can plug'n'play with mice or keyboards.
If anyone can help with the above questions I would certainly love to hear from you. If Kathy or Bert are reading this, I commend you on your efforts and I encourage you to write more books, but please, please, please, double, triple, quadruple check your code snippets. Your readers are beginners and beginners will blame themselves during compilation errors, they don't quite have the confidence or the knowledge to know when it's the source code that's the problem.
I'm going through the HeadFirt EJB book, and I stuck on one example. :< The
code is here (simple example used to illustrate simple ejb creation/usage,
but my example has that commented out).
import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;
import headfirst.*;
import javax.ejb.*;
public class AdviceClient{
public static void main( String[] args ){
System.err.println( "BEG" );
//new AdviceClient().go();
System.err.println( "END" );
public void go(){
Context ic = new InitialContext();
Object o = ic.lookup( "Advisor" );
AdviceHome home = (AdviceHome)PortableRemoteObject.narrow( o,
AdviceHome.class );
Advice advisor = home.create();
System.err.println( advisor.getAdvice() );
} catch( Exception ex ){

I can compile it with the right -classpath and all is good. But when I goto
run it, I get the error message java.lang.NoClassDefFoundError:
AdviceClient. Why?
As far as I can see the classname matches the public classname, there is a
public static void main( String[] ) method, and it compiles, but it can't
seem to find the main, why? I can create another simple code with
just the mainline and all runs correctly. Is there something with classpath
setup that screwing things up?
16 years ago