jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes package question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "package question" Watch "package question" New topic

package question

cornel jew
Ranch Hand

Joined: Jul 13, 2002
Posts: 37
Hi all
I am busy going through packages, but i have problems compiling the following code.Although A is compiling without any problems B is giving me the following error:
B.java:1: package packages does not exist
import packages.*;
B.java:6: cannot access A
bad class file: .\A.java
file does not contain class A
Please remove or make sure it appears in the correct subdirectory of the classpath.
{ A a = new A();
I saved the two files in d:\packages,cos my jdk is installed
on the D:\ drive.I also tried to save A.java in a sub directory of packages ,but that also did not work.
My classpath is as follows and i am using Win98:
PATH C:\WINDOWS;C:\WINDOWS\COMMAND;d:\j2sdk1.4.1_01\bin;%PATH%
I don't know if it is correct, cos i have read somewhere to do it this way.
Here is the code:
package packages;
public class A

import packages.*;
public class B
{int b;

public static void main(String args[])
{ A a = new A();
System.out.println("Starting B");
I don't know if i am doing it right, so please help.
Greg Charles

Joined: Oct 01, 2001
Posts: 2953

Hey Cornel Jew,
Wow, cool name! Far above Cayuga's waters ... at least someone is lighting a minora!
Well, anyway, A is in package packages. B is just in the default package. You should pick a directory, say c:\tmp, and put B.java in that directory. Then make a directory c:\tmp\packages and put A.java in there. From c:\tmp, do your classpath thing to get the current directory into the classpath. Now here's the trick, compile both classes at once:
javac B.java packages\A.java
Then, you can run it with:
java B
I agree. Here's the link: http://aspose.com/file-tools
subject: package question
jQuery in Action, 3rd edition