Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / January 2006

Tip: Looking for answers? Try searching our database.

Confused about how packages work.

Thread view: 
JoshRountree@gmail.com - 30 Jan 2006 05:37 GMT
Say I have these two classes, in separate files, MyTest.java,
MyOtherTest.java

package edu.newpack.test

class MyTest {

 MyOtherTest mOT;

 MyTest() {
 }
}

package edu.newpack.test

class MyOtherTest {

 MyOtherTest() {
 }
}

When I compile MyTest.java with javac MyTest.java in the directory
where both are located why does it say it cannot find MyOtherTest.java
.

Both files are in c:\sources\edu\newpack\test\
I can compile MyOtherTest.java just fine. If I import the package I
don't get the symbol not found error, but I thought if both classes
were in the same package I didn't have to import anything.

thanks
Roedy Green - 30 Jan 2006 06:06 GMT
>When I compile MyTest.java with javac MyTest.java in the directory
>where both are located why does it say it cannot find MyOtherTest.java

The practical solution to your problem is to say:

javac *.java

and be done with it let Javac sort it out. This is what you have to do
to deal with circular references anyway.

It probably makes it worse that your classes are not public.

The solution you will eventually home in on is using ant scripts to do
your builds. Then you let ant worry about it.

It is tricky figuring out when Javac will compile or recompile classes
other than the ones you explicitly asked it to compile. I have found
that relying on Java to do that nearly always leads to trouble,
especially when you have mixed -target specifications..  I explicitly
compile the library packages first then client packages, always a
whole package at a pop, always using ANT, which does it every so much
more quickly than you can from the command line loading javac.exe over
and over.

See http://mindprod.com/jgloss/javacexe.html
http://mindprod.com/jgloss/ant.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Stefan Schulz - 30 Jan 2006 11:31 GMT
Look at the -sourcepath and -classpath switches for javac. You might
wish to do -sourcepath C:\sources


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.