How to resolve packaging problem

I have created 2 packages
1) Pack3 2) Pack4
Pack3 contains MyClass1.java and
Pack4 contains MyClass2.java
but in actual java files ,I have given package names as Pack1 and Pack2 respectively......
package pack1;
public class MyClass1{
     public void find(){
          System.out.println("GOT..?");
package pack2;
import pack1.MyClass1;
public class MyClass2{
     public static void main(String args[]){
               MyClass1 m1=new MyClass1();
               m1.find();
               System.out.println("......");
If I COMPILE WHOLE SOURCE AT A TIME then it compiles correctly and create directories pack1 and pack2 and respective classes in those directories but IF I TRIED TO COMPILE ONLY PACK4 DIRECTORY....THEN IT FAILS TO COMPILE......AND GIVES ERROR AS PACK1 DOES NOT EXIST...this is quite obvious..because MyClass2.java refers to MyClass1.java which is in PACK1 and pack1 does not exist on disk.
How to solve this problem...?
I want to compile only single directory at a time...I mean HOW TO COMPILE ONLY PACK2 even though actual package name is different than directory name in which it resides...?and I am not getting why it compiles when I compile whole source at a time.
Thanks,
Archan
Edited by: Archana144 on Apr 25, 2008 7:17 AM

First off, Pack3 and Pack4 are not packages. If they were, they would be included in your package declarations.
When you compile a class, you need to include package roots and .jar files in the classpath such that all the classes you're using can be found. When you compile both classes at the same time, the compiler knows about both of them and can find them. When you only compile one of the classes, you need to tell the compiler where the package root for the other class is.
[Link to Packages Tutorial|http://java.sun.com/docs/books/tutorial/java/package/index.html]

Similar Messages

Maybe you are looking for

  • Using the fileReference class to upload image

    I've been using the loadVars to upload text and pass variables to php and onto the server. I've begun using the Flash Filereference class so an image can be uploaded directly from a Flash movie, not involving an html form. But within the Filereferenc

  • My HP C6300 All in one has suddenly stopped working

    Both Printer and Advent laptop tell me that they are both connected to my Netgear router but nothing happens. When I click on the printer logo all I recieve is an 'Error' message! I have tried everything on the support site without success. I am usin

  • BPM: warning from MTE's

    Hello! I am establishing Business Process Monitoring functionality. When I activate the monitoring I get a lot of warning "Could not change MTE customizing code 2 (MTE: <SID>\Dialog...\DBRequestTime)" <b>How critical are these warnings and how to avo

  • Cisco WLC 5508 assigning different SSID to few APs

    Hello Everyone, I have a WLC 5508 runing 8.0 Presently one SSID is assigned to all th APs registered with my WLC. I want a different SSID to 2 of APs. Can anyone tell me how to do this?

  • Error creating new album

    I just started with Elements 11 and imported my iPhoto library.  I am unable to delete pictures and get the above error when trying to create albums.  Any suggestions of why I can only have 3000+ folders and unable to organize?  I also tried to impor