aspose file tools*
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
Author

errors in importing packages.

Dushyant Shukla
Greenhorn

Joined: Jan 13, 2013
Posts: 13
I have file structre like this :
c:\javapractice\one\SomeFile.java
and
c:\javapractice\another\SomeOtherFile.java



Now when i try to compile SomeFile.java using the command
c:\javapractice\one>javac SomeFile.java
it compiles fine.
But when i try to compile SomeOtherFile.java using the command
c:\javapractice\another>javac SomeOtherFile.java
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
Bartender

Joined: Jan 28, 2003
Posts: 4174
    
  21

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\SomeFile.java
-- 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\SomeOtherFile.java
-- since -cp was set to C:\javapractice, the compiler knows to start looking there for one.SomeFile.class


Steve
Dushyant Shukla
Greenhorn

Joined: Jan 13, 2013
Posts: 13
Thanks Steve sir.
The problem is resolved.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: errors in importing packages.