• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt in package; compiling

 
raja kanak
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I copied the code found in K & B below

package book;
import cert.*; // Import all classes in the cert package
class Goo {
public static void main(String[] args) {
Sludge o = new Sludge();
o.testIt();
}
}
Now look at the second file:
package cert;
public class Sludge {
public void testIt() { System.out.println("sludge"); }
}

I placed Goo.java in the folder c:\scjp\book & the Sludge.java in c:\scjp\cert

Even though i successfully compiled Sludge.java Im unable to compile Goo.java

The error was "package cert does not exist"

I think the trick is behind classpath, how to fix it?
thanks in advance.
 
wise owen
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this
 
raja kanak
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you, wise owen

it compiles perfectly.

Now i try to run from the folder c:\scjp\book\
like c:\scjp\book\java Goo

but i got runtime exception as
Exception in thread main java.lang.NoClassDefFoundError: Goo (wrong name: book/Goo)

I just don't know what is going wrong!!!
 
wise owen
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this
c:\scjp\book>java -cp c:\scjp;. Goo
 
raja kanak
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by wise owen:
try this
c:\scjp\book>java -cp c:\scjp;. Goo


thanks for your efforts but SAME ERROR
 
anvesh charuvaka
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
go to directory scjp
and to execute the class type

Java book.Goo

[ This should work if your classpath is set to include the current directory which usually is ]
 
raja kanak
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that is great. It is working. thanks a lot.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic