Knight
Knight

Reputation: 573

Package Does Not Exist - JAVA

I have 3 classes:

TestPackages.java in c:\ws

package p1;
import p2.C;

public class TestPackages
{
public static void main(String[] args)
 {
    A a = new A();
    a.print();
    C c = new C();
 }
}

A.java in c:\ws

package p1;
public class A
{
public A(){

}
public void print()
{
    System.out.println("Dziala");
}

}

C.java in c:\ws2

package p2;

public class C
{
public C()
{
}

public void print()
{
    System.out.println("class C");
}
}

Compiled classes:

c:\ws\p1\A.class

c:\ws2\p2\C.class

When I set my classpath:

set classpath = c:\ws;c:\ws2

then go to c:\ws and compile:

javac -d . TestPackages.java

I get error: "package p2 does not exist"

Upvotes: 0

Views: 6178

Answers (1)

Balwinder Singh
Balwinder Singh

Reputation: 2282

You have set the classpath alright. Just change the following

javac -d . TestPackages.java

to following (when you are in c:\ws folder)

javac -d . p1\TestPackages.java

To add to my earlier comment, this has been explained in this link

Upvotes: 2

Related Questions