• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

AdviceClient Solution

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
After about three weeks of trying, i finally got the Advice App to run.
so, i have decided to share my experience with my fellow beginners.
All the steps and likely errors are listed below. Please for window users,
don't forget to replace : with ;


1. Most of the problems with EJB clients comes with the classpath.
if you run the AdviceApp and get,
Exception in thread "main" java.lang.NoClassDefFoundError: AdviceClient
it means your classpath isn't properly set by the -classpath of java. So do this,

java -classpath ./classes:/home/mimoh/j2sdkee1.3.1/lib/j2ee.jar: AdviceClient
You have to put : after the j2ee.jar

2. The problem isn't solved yet. if you run the client, you are going to get,

java.lang.ClassCastException
at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:293)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
at AdviceClient.go(AdviceClient.java:29)
at AdviceClient.main(AdviceClient.java:13)

3. Don't panic, the problem, isn't with your codes. All you have to do is add the client stub to the classpath.
Come to think of it, you are casting to what ? The client jar isn't found

java -classpath ./classes:AdviceAppClient.jar:/home/mimoh/j2sdkee1.3.1/lib/j2ee.jar: AdviceClient

Hulala !!! you should be happy with yourself, after getting something like

Visualise yourself with better cloths


4. Having problems setting the classpath, let see how to do it. Though, am using linux 9. it should work
for other OS. But, for Windows, replace the : with ; (don't miss it, else nightm... for you);

a.set the java home.JAVA_HOME="<java-dir path> eg replace "java-dir path" with the
actual location of your path.

b.Set the J2EE home.J2EE_HOME="<j2ee-dir path>

c. Add the JAVA_HOME/binto the system path
d.Add the J2EE_HOME/bin/j2ee.jar to the system path. So you can start the from anywhere.

e.To compile your codes, add;
javac -classpath ./classes:/home/mimoh/j2sdkee1.3.1/lib/j2ee.jar AdviceClient.java
the key here is the /lib/j2ee.jar.

f. To run your client.
java -classpath ./classes:AdviceAppClient.jar:/home/mimoh/j2sdkee1.3.1/lib/j2ee.jar: AdviceClient
the key here is AdviceAppClient.jar and for linux users you need to add : after the j2ee.jar: else
java will just be nice enough to return.

Exception in thread "main" java.lang.NoClassDefFoundError: AdviceClient

5. Hope, it helps, complements of the season to all the ranchers and associated families
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much. That sure will help others get around this problem in the future I'll bookmark this thread as well.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I set all the environment variables correctly as given in the website of wickedlysmart.com notes link..

But when I try to run itusing teh following command:

\projects\advice>javac -classpath {$CLASSPATH};AdviceAppClient.jar AdviceClient.java

I get teh follwoing errors. Could someone please help me out....

AdviceClient.java:5: package javax.ejb does not exist
import javax.ejb.*;
^
AdviceClient.java:26: cannot access javax.ejb.EJBHome
file javax\ejb\EJBHome.class not found
Advice advisor = home.create();
^
AdviceClient.java:28: cannot access javax.ejb.EJBObject
file javax\ejb\EJBObject.class not found
System.out.println(advisor.getMessage());
^
3 errors
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Saagar,

If you are on Windows, your command line should be

javac -classpath %CLASSPATH%;AdviceAppClient.jar AdviceClient.java
 
Saagar Kappa
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Valetin,

Thanq for ur suggestion. It worked and I got to compile the code.

But now when I try to run teh code using teh line

java -cp %CLASSPATH%;AdviceAppClient.jar AdviceClient

I get the excpetion as:

Exception in thread "main" java.lang.NoClassDefFoundError: AdviceClient

Now I tried, the one mentioned by Mohammed and then tried:
------------------------
java -classpath ./classes;AdviceAppClient.jar;/home/j2sdkee1.3.1/lib/j2ee.jar; AdviceClient
------------------------
and this is what i get

------------------------
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:22)
at AdviceClient.main(AdviceClient.java:14)
--------------------------------

Could you please guide me as to what to do??

Thanq once again..

Saagar.
 
MI Mohammed
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Saaga,
I haven't ran the AdviceClient on window, but try this

java -classpath ./classes;AdviceAppClient.jar;/home/mimoh/j2sdkee1.3.1/lib/j2ee.jar AdviceClient

and make sure your J2EE RI server is running.
Thanks.


SCJA SCJP SCWCD
 
Saagar Kappa
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mohammed,

The server is running and I tried:

java -classpath ./classes;AdviceAppClient.jar;/home/j2sdkee1.3.1/lib/j2ee.jar; AdviceClient

And I get
Exception in thread "main" java.lang.NoClassDefFoundError: AdviceClient

By teh way can u tell me what /home/mimoh/j2sdkee1.3.1 stands for?? I have the j2sdkee1.3.1 directly on teh C drive then what do I type in ??

Thanq
Saagar.
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi sagar,
read it carefully i have told the same thing to many other people and all windows user have been benifited by this and i am sure this will surely solve your problem..
set your environment variables as follows....

CLASSPATH C:\j2sdkee1.3.1\lib\j2ee.jar;D:\Certification\projects\advice

D:\Certification\projects\advice This is the folder where you will have your AdviceAppClient.jar file. see do not put the jar file name ok just the path to the directory. ok

J2EE_HOME C:\j2sdkee1.3.1

JAVA_HOME C:\jdk1.3.1_16

PATH C:\j2sdkee1.3.1\bin;C:\jdk1.3.1_16\bin;

ok now compile
javac -classpath %CLASSPATH%; AdviceAppClient.jar AdviceClient.java

and run the program
java -cp %CLASSPATH%; AdviceAppClient.jar AdviceClient

bingo....
it will run.
cheers
 
Saagar Kappa
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vikas,

I followed ur instructions and set everything as u said..

The code compiled but when I ran the program using

java -cp %CLASSPATH%; AdviceAppClient.jar AdviceClient

I get

Exception in thread "main" java.lang.NoClassDefFoundError: AdviceClient

I gave up on this and I am proceeding with the rest of teh chapters.

Thanks for ur concern though,

Saagar
 
MI Mohammed
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Saagar,
I'm sorry you have to go through this stress to run this app. Never mind,
as i said earlier, i haven't tried this app on window. But for you, i will download the J2EE over the weekend and get you the reply as soon as possible.
So just continue reading your HF EJB.
Have a lovely weekend of preparation.
Caio.

SCJA SCJP SCWCD SCBCD progr.....
 
vikas prasad
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear sagar,
check where you have put your AdviceAppClient.jar file you need to add the directory path to your CLASS path.
ok.
and still things doesnt work.
just try to start all over again.
may be uninstall and reinstall every things this might work.
and follow the previous instruction and i am sure it shoud work. i had similar problem and i did the same thing. and if you still have problem. then mail me all your code and path variable details may be then i can see and try to help.
my email is vikashprasad78@rediffmail.com
 
MI Mohammed
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Saagar,
I want to say thanks for taking me the window version of Advice App. Finally
i was able to solve the puzzle. Ok, here are the steps. We were actually close. Ok.

1. To compile (this for some other people like us).cd to advice directory.

C:\projects\advice>javac -d classes -classpath classes;C:\j2sdkee1.3.1\lib\j2ee.
jar src/headfirst/*.java

2. To run the client.

C:\projects\advice>java -cp classes;C:\j2sdkee1.3.1\lib\j2ee.jar;AdviceAppClient
.jar; AdviceClient
This was what i got;

Of course you don't have to go to work today.

Note.
1. The mistake was from the class path, you werw suppose to add ; at the end
of the classpath.

2. I found out that there is a bug, source not known,To detect the bug,check the error massages, you will see something like
Caused by: org.omg.CORBA.BAD_OPERATION: vmcid: 0x0 minor code: 0 completed:

So the way round it is to tweek the code a bit. Change the name of the business method to some thing very unique from the Advice interface.
Say to getMessage() and reflect same changes in the Bean class. Re-compile
and redeploy. Dont for to also change the method call from the client to
advisor.getMessage().
Have a kool day, hope you are free now. Wishing us all, the best in our
exams.



SCJA SCJP SCWCD SCBCD progr...
 
Saagar Kappa
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


finally after 1 whole week of ordeal i was able to run the program



Thanks a lot Mohammed. I really appreciate ur concern and guidance. I owe u one.

Special thanks to Vikas too for teh concern....



Saagar
 
MI Mohammed
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Saagar,
Thank you too, for for making me part of the ordeal. I owe you too.
I strongly belong to the school of thought that says "Winner's don't quit
and quitters never win "
Have a nice day.

SCJA SCJP SCWCD SCBCD progr.....
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What am I doing wrong?!?!

Here is my directory structure:
C:\Supriya\Java\J2EE\Tutorial\projects\AdviceBean :::: ROOT directory

(i) AdviceAppClient.jar is contained here
(ii) classes is a subdirectory here. contains the package com.advicebean.AdviceBeanClient

My %CLASSPATH% settings: .;C:\j2sdk1.4.2_08\lib;C:\Sun\AppServer\lib;C:\Sun\AppServer\lib\j2ee.jar;

To run my Advisor, I -
(i) cd C:\Supriya\Java\J2EE\Tutorial\projects\AdviceBean
(ii) java -cp %CLASSPATH%AdviceAppClient.jar;classes; com.advicebean.AdviceBeanClient

and then the famous exception -

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial

I know i'm missing something from all your posts and there really is no excuse for that... But i have tried to redo this for teh past 2 days and still unable to find what i'm doing wrong... Can someone please tell me where I am messing up?? Would be really really appreciated....
 
Saagar Kappa
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Supriya,

One thing I would suggest is that you download j2sdk_1.2 instead of 1.4 and then reset your java_home for that..

Then try running your app, this problem would be solved but u mite get some other problems. If u do lemme know and I can probably help u out. I have had a hard time with this example too..

Cheers,
Saagar
 
Supriya Vaidya
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Saagar..

It didn't work though - I did try that, but after a bunch of other changes, come down to the same problem:
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial

Help..
 
Supriya Vaidya
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
alllllright!!! Got it FINALLY.. I guess it pays to listen to Kathy when she sez use J2EE 1.3... So anyway.. here's what I did: Yes, j2ee.jar is needed in the classpath, but we also need \lib\appserv-rt.jar for the jndi.properties and other naming related classes. Got it to run - and now I can move on to the next chapter happily!! (sorry - can't stop grinning!)
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by mi Mohammed:
Saaga,
I haven't ran the AdviceClient on window, but try this

java -classpath ./classes;AdviceAppClient.jar;/home/mimoh/j2sdkee1.3.1/lib/j2ee.jar AdviceClient

and make sure your J2EE RI server is running.
Thanks.


SCJA SCJP SCWCD





Thanks for the tips!!!
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am facing the same problem;

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial

I have checked all the steps.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am working on windows and have set all the paths properly, and also changed the name from getAdvice() to getTheMessage(). Still I am getting following error. please help me out.

Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/corba/se/inte
rnal/util/JDKBridge
at com.sun.corba.ee.internal.core.IOR$LocalCodeBaseSingletonHolder.<clin
it>(IOR.java:90)
at com.sun.corba.ee.internal.core.IOR.<init>(IOR.java:238)
at com.sun.corba.ee.internal.iiop.messages.LocateReplyMessage_1_2.read(L
ocateReplyMessage_1_2.java:137)
at com.sun.corba.ee.internal.iiop.IIOPInputStream.unmarshalHeader(IIOPIn
putStream.java:126)
at com.sun.corba.ee.internal.iiop.IIOPConnection.getResponse(IIOPConnect
ion.java:671)
at com.sun.corba.ee.internal.iiop.IIOPConnection.send(IIOPConnection.jav
a:778)
at com.sun.corba.ee.internal.corba.InitialNamingClient.locateObject(Init
ialNamingClient.java:786)
at com.sun.corba.ee.internal.corba.InitialNamingClient.getIORUsingHostIn
fo(InitialNamingClient.java:597)
at com.sun.corba.ee.internal.corba.InitialNamingClient.resolveCorbaloc(I
nitialNamingClient.java:573)
at com.sun.corba.ee.internal.corba.InitialNamingClient.resolveUsingORBIn
itRef(InitialNamingClient.java:544)
at com.sun.corba.ee.internal.corba.InitialNamingClient.cachedInitialRefe
rences(InitialNamingClient.java:1080)
at com.sun.corba.ee.internal.corba.InitialNamingClient.resolve_initial_r
eferences(InitialNamingClient.java:981)
at com.sun.corba.ee.internal.corba.ORB.resolve_initial_references(ORB.ja
va:2425)
at com.sun.enterprise.naming.SerialContext.getProvider(SerialContext.jav
a:52)
at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:120
)
at javax.naming.InitialContext.lookup(Unknown Source)
at AdviceClient.go(AdviceClient.java:17)
at AdviceClient.main(AdviceClient.java:10)
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic