File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes errors in importing packages. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "errors in importing packages." Watch "errors in importing packages." New topic

errors in importing packages.

Dushyant Shukla

Joined: Jan 13, 2013
Posts: 13
I have file structre like this :

Now when i try to compile using the command
it compiles fine.
But when i try to compile using the command
it gives the error
package one doesn't exist
import one.SomeFile;

After some study i got to know that this can be the problem associated with classpath....,but still i am not able to fix it.
Please suggest some remedy.
Steve Luke

Joined: Jan 28, 2003
Posts: 4181

This is a classpath issue. The classpath is the folder under which all of your packages and classes can be found. You have two packages, one and another. These two packages are both in C:\javapractice, so C:\javapractice needs to be in your classpath. Here is how you do it:

1: Navigate to C:\javapractice\ to do all your compiling (the root of your classpath).
2: Type in javac -cp . one\
-- the -cp sets the classpath, then a space then a period. The period means 'this folder'. So -cp . means 'set the classpath to the current folder'
3: Type in javac -cp . another\
-- since -cp was set to C:\javapractice, the compiler knows to start looking there for one.SomeFile.class

Dushyant Shukla

Joined: Jan 13, 2013
Posts: 13
Thanks Steve sir.
The problem is resolved.
I agree. Here's the link:
subject: errors in importing packages.
It's not a secret anymore!