aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes compiling package with import statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "compiling package with import statement" Watch "compiling package with import statement" New topic

compiling package with import statement

Linda Pan
Ranch Hand

Joined: Sep 24, 2001
Posts: 96
I've been trying to get this working .... I have 2 classes where one class uses an import statement.

My file structure is c:\Sierra\java where both the Goo and Sludge java files are located. I can compile Sludge using c:\Sierra\java> javac -d c:\Sierra\classes and class Sludge is correctly created in the cert folder. When I try to do the same with Goo, I get compile errors: "package cert does not exist" and "cannot resolve symbol" when it attempts to create an instance of Sludge.
I am using 1.4.1 compiler. What am I doing wrong? I was trying to keep my class vs java files in separate as recommended in previous posts.
[ March 28, 2003: Message edited by: Linda Pan ]
Jessica Sant

Joined: Oct 17, 2001
Posts: 4313

you can't have two classes in different packages be defined in the same file.
Try breaking it up to two files -- and all should be fine.
Linda Pan
Ranch Hand

Joined: Sep 24, 2001
Posts: 96
I got it working ... it appears as long as I have Sludge in the cert subdirectory, and Goo in the book subdirectory, I can compile both files using c:\Sierra\java> javac cert/ book/ I can run java book/Goo and get my output.
Linda Pan
Ranch Hand

Joined: Sep 24, 2001
Posts: 96
I was also working with source files in the c:\Java path. When compiling I would get the class not found compile error. Resolved my problem by setting the classpath in autoexec.bat file.
wood burning stoves
subject: compiling package with import statement
Similar Threads
Package problem
Command to run when files are in different package
doubt in package; compiling
Public Members access
Compiling multiple source files