The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
April 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Importing user-defined packages and classpath problems

Posted by Genie on May 17, 2001 at 4:30 AM

I'm very new to java programming so please bear with me.
I've got a problem with creating and importing own packages. I need your advice.Thankyou.
Say i've two classes: Point class and Rectangle class in the dir.
D:\Java\Examples\graphics\Point.java
D:\Java\Examples\graphics\Rectangle.java
Both have package graphics; at the beginning of each java file.
Like this: package graphics;
public class Point {
... ...
}

package graphics;
public class Rectangle {
... ...
}

So as for the main java program (CreateObject.java) in this directory:
D:\Java\Examples\CreateObject.java
1st question: Do i need to put this main program in the same dir as the two java files above?

I've read about the classpath problem mentioned by Kishori and did the following:
D:\Java\Examples\javac -classpath CreateObject.java
It can compile but when i run it,
D:\Java\Examples\java -classpath CreateObject.java
it has the following error:
Usage: Java -[options] class -[args]
......
......

so i tried to compile and run like this:
D:\Java\Examples\java -cp -classpath CreateObject.java
Now it has this error:
Exception in thread "main" java.lang.NoClassDefFoundError: CreateObject

What is the problem?






Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us