wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt in package; compiling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt in package; compiling" Watch "doubt in package; compiling" New topic
Author

doubt in package; compiling

raja kanak
Ranch Hand

Joined: Oct 18, 2006
Posts: 135
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.


live
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
try this
raja kanak
Ranch Hand

Joined: Oct 18, 2006
Posts: 135
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

Joined: Feb 02, 2006
Posts: 2023
try this
c:\scjp\book>java -cp c:\scjp;. Goo
raja kanak
Ranch Hand

Joined: Oct 18, 2006
Posts: 135
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

Joined: Sep 25, 2006
Posts: 11
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

Joined: Oct 18, 2006
Posts: 135
that is great. It is working. thanks a lot.
 
Consider Paul's rocket mass heater.
 
subject: doubt in package; compiling
 
Similar Threads
Command to run when files are in different package
Package problem
Run time error
compiling package with import statement
Compiling multiple source files