当前位置: 动力学知识库 > 问答 > 编程问答 >

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"

网友答案:

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

分享给朋友:
您可能感兴趣的文章:
随机阅读: