Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Help with compiling AdviceClient.java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Help with compiling AdviceClient.java" Watch "Help with compiling AdviceClient.java" New topic
Author

Help with compiling AdviceClient.java

Unnsse Khan
Ranch Hand

Joined: Nov 12, 2001
Posts: 511
I am on page 57 of the Head First EJB book, and so far, I have followed all the instructions to a tea...
I am running Linux (Red Hat 9.0) with the Java 2 EE 1.3 reference implementation...
When I tried to compile the AdviceClient.java file, this is what happened:
---------------------------------------------------------------------------
javac -classpath {$CLASSPATH}:AdviceAppClient.jar AdviceClient.java
AdviceClient.java:3: package javax.ejb does not exist
import javax.ejb.*;
^
AdviceClient.java:24: cannot resolve symbol
symbol : class AdviceHome
location: class AdviceClient
AdviceHome home = (AdviceHome) PortableRemoteObject.narrow(o, AdviceHome.class);
^
AdviceClient.java:24: cannot resolve symbol
symbol : class AdviceHome
location: class AdviceClient
AdviceHome home = (AdviceHome) PortableRemoteObject.narrow(o, AdviceHome.class);
^
AdviceClient.java:24: cannot resolve symbol
symbol : class AdviceHome
location: class AdviceClient
AdviceHome home = (AdviceHome) PortableRemoteObject.narrow(o, AdviceHome.class);
^
AdviceClient.java:26: cannot resolve symbol
symbol : class Advice
location: class AdviceClient
Advice advisor = home.create();
^
5 errors
----------------------------------------------------------------------------
Yikes! I don't know where the error is and I don't know where to start and if I have to re-jar everything and also deploy everything all over again using the 'deploytool'...
Here's some information regarding my environment:
my CLASSPATH:
echo $CLASSPATH
/usr/java/j2sdk1.4.2_02/lib/tools.jar:/usr/java/j2sdk1.4.2_02/jre/lib/rt.jar:/usr/java/j2sdkee1.3/lib/j2ee.jar
My current directory's path is:
/usr/local/proj/headfirst
After and ls -l here are the files:
root 8654 Nov 9 22:21 AdviceAppClient.jar
root 3434 Nov 9 22:21 AdviceApp.ear
root 872 Nov 9 22:35 AdviceClient.java
root 303 Nov 9 21:46 cloudscape.LOG
root 4096 Nov 9 21:44 cls
root 2314 Nov 9 22:11 ejb_temp60765.jar
root 2537 Nov 9 22:21 ejb_temp60769.jar
root 4096 Nov 9 21:43 src
Another question, what are the ejb_temp*.jars? The book didn't mention the anything about the RI creating these (this is question is not as important as the help I need to successfully compile AdviceClient.java, but I figured I'd ask anyway)...
Please help, as I do want to proceed through the book and take the exam!
Any help, suggestions, tips, etc, will be appreciated...
Mikalai Zaikin
Ranch Hand

Joined: Jun 04, 2002
Posts: 3211
    
    6
Isn't it say that javax.ejb.* classes are not in the CLASSPATH ???


Free SCDJWS 5.0 Study Guide - SCDJWS 5.0 Quiz (How to get SCDJWS 5.0 Quiz)
Java Platform, Enterprise Edition 6 Web Services Developer Certified Expert Exam Study Guide and Quiz
Unnsse Khan
Ranch Hand

Joined: Nov 12, 2001
Posts: 511
Not finding the "javax.ejb.*" package is false, because I compiled the the Bean class, the component interface, and the home interface, without any errors...
Also my classpath has the j2ee.jar appended at the end of it (the location of the javax.ejb.* package).
I get the aforementioned error when I tried to compile the client class that speaks to the EJBObject...
Can anyone help me on this?
Unnsse Khan
Ranch Hand

Joined: Nov 12, 2001
Posts: 511
Nobody can help me at all with this?
Anselm Paulinus
Ranch Hand

Joined: Sep 05, 2003
Posts: 389
Ok since you said suggestions and tips are welcomed.
I had a case where my EJB classes did not see the javax.ejb that was imported using the import statement. All I did to rectify the problem was to mount javax.ejb and the error was rectified. I was actually using NetBeans for development. I do not know if this has any bearing with what you are currently going through.
anselm.
Sarma Lolla
Ranch Hand

Joined: Oct 21, 2002
Posts: 203
Just verify [B]which java [B] from command window. Because I was getting similar error some time back and then I realized that instead of accessing the jdk1.4 from weblogic it was using jdk1.3 from cygwin. When I rectified my path every thing went of well.
Kathy Sierra
Cowgirl and Author
Ranch Hand

Joined: Oct 10, 2002
Posts: 1572
Howdy -- OK, let's try to figure out what's going on!
It does look like you have everything set-up correctly, and yet the compile error *looks* like a classpath problem. It can't find the j2ee.jar. Yet you already know it's on the classpath correctly because:
1) You were able to successfully compile the interfaces and the bean
2) You can *see* that the j2ee.jar is on the classpath when you echo it.
So... hmmm... the only difference between the way in which you compiled the bean and interfaces versus the way in which you are compiling the client is the -classpath flag.
The only thing I can think of right now, is to verify that this is the correct syntax for the shell that you are using:
javac -classpath {$CLASSPATH}:AdviceAppClient.jar ...
In other words, are you certain that the [BOLD]{$CLASSPATH}: [/BOLD] works correctly with your current shell? Because it does *act* like javac can no longer see what is on your existing classpath, even though your command-line looks right to me.
Please let me know if you've verified that, because that -classpath is the only thing different between how you compiled (successfully) the other classes and this one.
One way or another, we'll figure it out!
cheers,
Kathy
Calvin Kong
Ranch Hand

Joined: Jul 02, 2003
Posts: 37
I got RemoteException while running AdviceClient:
C:\calvin\j2ee_projects\projects\advice>java -cp %CLASSPATH%;AdviceAppClient.jar
AdviceClient
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(Class.java:232)
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(ObjectImpl.java:454)
at headfirst._Advice_Stub.getAdvice(Unknown Source)
at AdviceClient.go(AdviceClient.java:27)
at AdviceClient.main(AdviceClient.java:9)
Anybody can help?
Thanks
Cal


Cal<br />SCJP,SCWCD,SCBCD
Anthony Watson
Ranch Hand

Joined: Sep 25, 2003
Posts: 327
I got the same error as Calvin Kong.
Unnsse Khan
Ranch Hand

Joined: Nov 12, 2001
Posts: 511
Kathy,
Thank you very much for responding! I am very pysched to learn EJB! I can't believe how technologically advanced EJB's are!
Ok, this is my theory... I think that in Red Hat 9.0, the ${CLASSPATH} is incorrect way to do things... I think by omitting the curly braces '{' & '}' will help alleviate my problem... In other words, maybe I should have used:
javac $CLASSPATH: jar_file java_source_file
Also I think another solution would be to write an build.xml script (with my CLASSPATH specified) and then try to execute the Client application...
BTW, what platform do you develop on? And what tools do you use? I use Red Hat 9.0 and Windows 2000 Professional for the platform. I also use gVim for both systems, and have played around with Eclipse...
I'll try out my theories, and then get back to all of you great folks at JavaRanch!
Unnsse Khan
Ranch Hand

Joined: Nov 12, 2001
Posts: 511
Cheers! I have over a hundred posts now, on JavaRanch (I know compared to others its not impressive, but hey! I am getting there)
Cheers! And happy studying & computing!
Unnsse Khan
Ranch Hand

Joined: Nov 12, 2001
Posts: 511
Ok, there some good news & bad news... &
The good:
when I tried my theory with:
javac -classpath $CLASSPATH:AdviceAppClient.jar AdviceClient.java
the first error was gone!
now there are 4 errors:
----------------------------------------------------------------------------
AdviceClient.java:24: cannot resolve symbol
symbol : class AdviceHome
location: class AdviceClient
AdviceHome home = (AdviceHome) PortableRemoteObject.narrow(o, AdviceHome.class);
^
AdviceClient.java:24: cannot resolve symbol
symbol : class AdviceHome
location: class AdviceClient
AdviceHome home = (AdviceHome) PortableRemoteObject.narrow(o, AdviceHome.class);
^
AdviceClient.java:24: cannot resolve symbol
symbol : class AdviceHome
location: class AdviceClient
AdviceHome home = (AdviceHome) PortableRemoteObject.narrow(o, AdviceHome.class);

^
AdviceClient.java:26: cannot resolve symbol
symbol : class Advice
location: class AdviceClient
Advice advisor = home.create();
^
4 errors
[root@localhost headfirst]# clear

[root@localhost headfirst]# javac -classpath $CLASSPATH:AdviceAppClient.jar AdviceClient.java
AdviceClient.java:24: cannot resolve symbol
symbol : class AdviceHome
location: class AdviceClient
AdviceHome home = (AdviceHome) PortableRemoteObject.narrow(o, AdviceHome.class);
^
AdviceClient.java:24: cannot resolve symbol
symbol : class AdviceHome
location: class AdviceClient
AdviceHome home = (AdviceHome) PortableRemoteObject.narrow(o, AdviceHome.class);
^
AdviceClient.java:24: cannot resolve symbol
symbol : class AdviceHome
location: class AdviceClient
AdviceHome home = (AdviceHome) PortableRemoteObject.narrow(o, AdviceHome.class);

^
AdviceClient.java:26: cannot resolve symbol
symbol : class Advice
location: class AdviceClient
Advice advisor = home.create();
^
4 errors
----------------------------------------------------------------------------
This is what I did...
1) I logged into Linux.
2) I started the J2EE RI server by:
j2ee -verbose
Everthing had started perfectly...
3) I attempted to recompile the client application...
Am I supposed to redeploy everything all over again using 'deploytool'? And then attempt to compile the client app?
Does anyone recognize my problems?
Would it help if I appended my proj directory to my CLASSPATH, permanently?
Again, any criticisms, suggestions, hints, advice, are warmly welcomed ...
Kathy Sierra
Cowgirl and Author
Ranch Hand

Joined: Oct 10, 2002
Posts: 1572
Hey, this is actually fun... kind of After all this time, it's just hard to believe that people are finally running (er, *trying* to run) this code
OK, Calvin and Anthony, not sure what the problem is offhand. You've obviously passed the JNDI lookup OK, and gotten back the home, and invoked create() on the home successfully. It's only when you actually tried to *use* what you got back from the home that it is failing.
So... here's my first step: put in a System.out.println right after the create() to see what you got BACK from create(). In other words, what are you calling getAdvice() on? We'll start there... You *might* try restarting the server, since you're using the RI. I do not think this is a deployment problem, but we'll see.
Now, Unnsse -- first things first -- congratulations on your hundred posts!!
Back to *your* problem -- well, we knocked out the first problem, with the environment variable syntax, so that's good. I should have mentioned something about how this will vary depending on your shell!
But now that you have most of the hard stuff working (bean deployed, etc.) it looks like a simple package problem now. Here's some stuff to verify:
1) Do you have the right import statement in the client? (if you're following the code in the book, you should have
2) When you put the classes into the ejb-jar (using deploytool) are you certain that they came in *with* their packages? In other words, inside the jar, you must have headfirst/Advice (etc.). I am pretty certain that this is NOT the problem, since you deployed correctly, but you might want to check. The way to check is in the deploytool -- somewhere in the main window you can click around and list the contents of the jar (I don't have it up now so I can't remember where it is).
3) Check the name of the client jar (no, never mind, I just looked at your ls and your command-line and that looks fine, but I'm leaving it in here because that's FREQUENTLY a problem people have.)
Don't worry; I'm not going anywhere. We'll get to the bottom of it.
cheers,
Kathy
Calvin Kong
Ranch Hand

Joined: Jul 02, 2003
Posts: 37
Dear Kathy,
I added a System.out.println() right after the "Advice advisor = home.create();" and the text was printed out. So the problem happened when it called the business method getAdvice(). I've retried after restarting RI and the RemoteException still occured.
Help!Help!Help!
Thanks
Cal
Kathy Sierra
Cowgirl and Author
Ranch Hand

Joined: Oct 10, 2002
Posts: 1572
Howdy Calvin,
OK, here's what I *really* want to know:
Advice advisor = home.create();

System.out.println("advisor is " + advisor);
I just want to know exactly WHAT is coming back from create().
But here's another thing to try -- and if you're gonna practice with EJB, you might as well get used to it now
1) Go into your bean class and stick a System.out.println("in getAdvice()") or something in your getAdvice() method.
2) Recompile your bean class
3) Go back to the deploytool and choose tools > update and redeploy (I think that's what it is called). You should see some kind of message that shows things have changed... don't worry about anything it says UNLESS it says that "all files are up to date", in which case it didn't see that you changed the bean class, so make sure that you've saved it with your changes and recompiled it. The deploytool KNOWS where your class files are, so it will automatically check to see if they've changed, and if so, it will replace the ones in the ejb-jar with these newly-changed classes. Click OK or whatever it is to dismiss that message and you'll see the deploytool start cranking out a redeploy. It will happen quickly, and shouldn't cause any problems.
4) Then run your client again.
You should NOT have to re-create your bean jar -- that's a desperate act.

If you don't get any useful info from either of these things, about what the problem might be, then you *might* have to do one of these things (listed in order of pain -- start with the first one and if that doesn't work, try the second).
REDEPLOY
========
[this forces the server to recreate the stub and implementation classes]

1. In the deploytool, locate the server icon and select your deployed application (lower right side of the main deploytool screen -- NOT under applications, but under servers). You should see an "undeploy" button in the main display window. (I'm not remembering where it is perfectly, but somewhere you'll see it...)
2) Choose "undeploy"
3) shut down J2EE
4) shut down deploytool
5) look for any ejb-temp jars and delete them
6) restart J2EE
7) restart deploytool
8) select your application and choose tools > deploy to redo the deploy process (you'll see the bars go up, be sure to click "return client jar", etc.)
9) Now run your client again.

IF THAT DOESN"T WORK... CLEANUP
========================
1) Go to a new terminal and type "cleanup" (without the quotes). If you're on windows NT, or some other system that has something named 'cleanup', you might have to disable it. Anyway, cleanup is a J2EE script that will restore the server back to its original state, cleaning out logs and everything. Which means your bean will be undeployed.
2) Make sure the server is shut down (I think cleanup will prompt you)
3) Shut down deploytool
4) Restart J2EE server
5) Restart deploytool
6) Select your AdviceApp in deploytool and tools > deploy to do a whole new deploy.
7) Now run your client again.
Sometimes things become corrupt, and this fixes it. Oh yeah, track down all of those temp jars and DELETE them before redeploying.

These are general trouble-shooting tips regardless of the problem (well, unless you can see that it is a classpath problem, which usually means that the problem is NOT in the server or deployed application, but is instead some kind of configuration / set-up problem).
cheers,
Kathy
We'll get there!
Calvin Kong
Ranch Hand

Joined: Jul 02, 2003
Posts: 37
Kathy,
I've put the System.out.println and this is the output:
advisor is: IOR:0000000000000026524d493a6865616466697273742e4164766963653a303030
30303030303030303030303030000000000000010000000000000164000102000000000c3139322e
3136382e302e32000762000000000041afabcb0000000024d27820e9000000010000000000000001
0000000d5472616e7369656e74504f410000000000000010d2784cb0000000000000000400000001
0a000000000000050000000100000020000000000001000100000002050100010001002000010109
0000000100010100000000210000007c000000000000000100000000000000240000001e00000066
00000000000000010000000c3139322e3136382e302e320007630040000000000000000806066781
02010101000000170401000806066781020101010000000764656661756c74000400000000000000
000000010000000806066781020101010000000f0000001900000031000000000000002968747470
3a2f2f77696e326b7376723a393139312f416476696365417070436c69656e742e6a617200000000
0000001f0000000400000003000000200000000400000001
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(Class.java:232)
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(ObjectImpl.java:454)
at headfirst._Advice_Stub.getAdvice(Unknown Source)
at AdviceClient.go(AdviceClient.java:28)
at AdviceClient.main(AdviceClient.java:9)
Let me try your steps now and see if it works

Thanks
Cal
Aravind, Lakkavajhula
Greenhorn

Joined: Aug 12, 2002
Posts: 2
Ki Kathy/Calvon,
After having bought the HeadFirst book and tried the first example, Even i ran into the same problem for about 3 days.
I havent had a chance to try what Kathy had suggested [System.out.printlns stmts] however i tried doing the rest of the steps[undeploy,cleanup,deploy etc] number of times[over past 3 days] but in vain.
Finally, it worked.
I removed the package headfirst statement in all my AdviceHome, Advice, AdviceBean
and removed the import headfirst stmt in AdviceClient. Kept all the classes looose in projects\advice\classes directory and client in projects\Advice directory
Rest of the steps have been followed by book.
It worked fine now without throwing the Corba exception.
But am curious to find out why it fails when i package them?

Aravind
Aravind, Lakkavajhula
Greenhorn

Joined: Aug 12, 2002
Posts: 2
Prior to getting the error message posted by Calvin, i also got the
the following message .
java.rmi.RemoteException: CORBA BAD_OPERATION 0 No; nested exception is:
org.omg.CORBA.BAD_OPERATION: vmcid: 0x0 minor code: 0 completed: No
at com.sun.corba.ee.internal.iiop.ShutdownUtilDelegate.mapSystemExceptio
n(ShutdownUtilDelegate.java:137)
at javax.rmi.CORBA.Util.mapSystemException(Util.java:65)
at headfirst._Advice_Stub.getAdvice(Unknown Source)
at AdviceClient.go(AdviceClient.java:23)
at AdviceClient.main(AdviceClient.java:11)
Caused by: org.omg.CORBA.BAD_OPERATION: vmcid: 0x0 minor code: 0 completed:
No
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct
orAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC
onstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at java.lang.Class.newInstance0(Class.java:306)
at java.lang.Class.newInstance(Class.java:259)
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(ObjectImpl.java:457)
at headfirst._Advice_Stub.getAdvice(Unknown Source)
... 2 more
I dont remember what i did except installing jdk1.3.1 instead of jdk1.4
and reverifying classpath.
Later started getting the error mentioned by calvin. And this got fixed by puuting the classes out of the package headfirst.
Hope this does not add more to the confusion
Aravind
Kathy Sierra
Cowgirl and Author
Ranch Hand

Joined: Oct 10, 2002
Posts: 1572
Hmmmmm... Aravind, if you (or anyone else) is having trouble with the packages it *could* be that the package structure is not going into the JAR *with* the correct directory structure. If you put only the classes *without* the headfirst (i.e. the package) directory in the JAR, then it won't work at runtime. If the classes *say* they are in a package, then that package structure (and no OTHER directories except the package directory, headfirst) MUST be in the JAR.
The problem is, when you use the deploytool, that the part where you add the classes is sometimes *really* difficult to get that structure into the JAR correctly. The user interface is really confusing, and is an area a lot of people have issues with.
I'm at least glad that you got it working Aravind! Now we have to get Calvin working...
cheers,
Kathy
Calvin Kong
Ranch Hand

Joined: Jul 02, 2003
Posts: 37
Kathy,
I've tried the steps you provided many times and still got the RemoteException (even after cleanup, for many times), and the print statement inside getAdvice() was never called....
Then I tried Aravind's method by removing the package headfirst, and it worked finally.
I wonder why the package structure ruined the work? It shouldn't be right?
Thanks
Cal
Matt Gaunt
Ranch Hand

Joined: Sep 05, 2003
Posts: 34
Hi All,
Not sure what systems you are using. I am using Win2K trying to get the AdviceGuy to work also.
Kathy has posted a response to this same problem here
http://www.coderanch.com/t/312836/EJB-JEE/java/Head-First-EJB-st-tut
Appears there is a bug in 'some' versions of the RI whereby the name of the method within the remote interface and bean, cannot contain the name of the interface. So in the AdviceGuy case, the interface name is 'Advice', nad the method we are tyring to call is 'getAdvice()'. I changed the method name to 'getMessage()' in the interface and in the bean, redeployed and it all worked perfectly.
Thanks Kathy.
Best Regards
Matt
Sudhansu Pati
Ranch Hand

Joined: Sep 23, 2003
Posts: 77
Thank you Matt,
That was the trick. Seems like getAdvice() method in AdviceBean causes issues. I changed that to getMessage() and it worked.


Sudhansu<br />SCJP, SCWCD, SCBCD, SCJD, SCEA, SCDJWS
 
GeeCON Prague 2014
 
subject: Help with compiling AdviceClient.java