wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes basic packages question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "basic packages question" Watch "basic packages question" New topic

basic packages question

John Rumassin

Joined: Apr 13, 2007
Posts: 4
i have 2 files, in two separate folders.


package myPackage;

public class test {
public test()

package myPackage2;

import myPackage.test;

public class test2
public static void main (String[] args)

i can compile test.java. when i try and compile test2.java it says "package myPackage does not exist". the error code then follows with the statement "import myPackage.test".

i only have one classpath which is "."

on another computer it works fine and on mine it doesn't! help, please!

this is a simplistic example and i know you can do classpath ".." but i want it work without this as it is not necessary on another machine (and in my complicated . my machine is windows 2000 with 1.5.11 and the machine it works on is xp with 1.6.0
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11441

"java beginner"

Please go back and read our Naming Policy. At the bottom of that page, you will find a link to change your display name. This is one of the two policies here that is strictly enforced - the other being "Be Nice".

Once you have done that, i'm sure someone will be glad to help you with your problems.
[ April 13, 2007: Message edited by: Fred Rosenberger ]

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
John Rumassin

Joined: Apr 13, 2007
Posts: 4
sorry. i changed my name will apply by the rules. john
Srikanth Ramu
Ranch Hand

Joined: Feb 20, 2007
Posts: 76
While compiling your test.java use below command:

javac -d . test.java

you will find myPackage\test.class file created.

Now compile your test2.java as

javac -d . test2.java

you will find myPackage2\test2.class file created.

Hope this helps
John Rumassin

Joined: Apr 13, 2007
Posts: 4
thank you for the response. i will give it a try. i thought -d was for system properties? is this something with windows 2000 vs xp? why wouldn't i need the -d on one computer but i would need it on another? thanks in advance, john
Joanne Neal

Joined: Aug 05, 2005
Posts: 3720
The -d option specifies where the class files should be created. It has nothing to do with your problem.
What directory are you in when you compile test2.java ?
If you only have "." in your classpath, then you need to be in the directory that the myPackage directory is a sub-directory of. If you are in the mypackage2 directory, then you need to specify that parent directory in your classpath.
e.g. if myPackage is a sub-directory of source, use the command line
javac -cp source myPackage2\test2.java

[ April 13, 2007: Message edited by: Joanne Neal ]
[ April 13, 2007: Message edited by: Joanne Neal ]

John Rumassin

Joined: Apr 13, 2007
Posts: 4
thank you for the reply. i know that i can add -cp ".." and it will recognize the above directory and compile. but this is not necessary on one machine and it is necessary on the other. i have checked the environmental variables and found that the only directory is ".". i am wondering if it is not a classpath issue? the code above is all the code. if you have the following file structure, please try it:


compile both files (without the use of defining the classpath). thanks to all for the help, John
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
See if THIS describes your situation ... under Using Packages.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link: http://aspose.com/file-tools
subject: basic packages question