Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

basic packages question  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have 2 files, in two separate folders.

\myPackage\test.java
\myPackage2\test2.java

//test.java
package myPackage;

public class test {
public test()
{}
}

//test2.java
package myPackage2;

import myPackage.test;

public class test2
{
public static void main (String[] args)
{
System.out.println("hello");
}
}

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
 
lowercase baba
Posts: 12746
51
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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 ]
 
John Rumassin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry. i changed my name will apply by the rules. john
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

c:\myPackage
c:\myPackage2

compile both files (without the use of defining the classpath). thanks to all for the help, John
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See if THIS describes your situation ... under Using Packages.
 
The first person to drink cow's milk. That started off as a dare from this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!