This week's book giveaway is in the Agile forum.
We're giving away four copies of The Software Craftsman and have Sandro Mancuso on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes java -cp question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java -cp question" Watch "java -cp question" New topic

java -cp question

Anthony Smith
Ranch Hand

Joined: Sep 10, 2001
Posts: 285
I am working with google apis.
I created a java file called mygoogle with no package and placed it directly in the root directory of my google folder. Also in the root directory of my google folder is the googleapi.jar file that is needed to compile and run mygoogle. I can compile mygoogle just fine but I cannot run it. From the google directory I do:
java -cp googleapi.jar mygoogle 1234PVQFHIpUjaP10MscjPLxgJQy1U5 search Foo
and I get:
Exception in thread "main" java.lang.NoClassDefFoundError: mygoogle
How do I get around that?
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9056
In addition to including the jar, you need to also include your base directory in your classpath. For example,

java -cp C:\google\googleapi.jar;C:\google mygoogle 1234PVQFHIpUjaP10MscjPLxgJQy1U5 search Foo

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 641
If u can also try this
java -cp C:\google\googleapi.jar;. mygoogle 1234PVQFHIpUjaP10MscjPLxgJQy1U5 search Foo

All desirable things in life are either illegal, banned, expensive or married to someone else !!!
Anthony Smith
Ranch Hand

Joined: Sep 10, 2001
Posts: 285
Thanks guys both worked!
I agree. Here's the link:
subject: java -cp question