wood burning stoves 2.0*
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 Android Security Essentials Live Lessons this week in the Android 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 Sludge.java 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/Sludge.java book/Goo.java. 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.
I agree. Here's the link: http://aspose.com/file-tools
subject: compiling package with import statement
Similar Threads
Public Members access
Command to run when files are in different package
Package problem
doubt in package; compiling
Compiling multiple source files