Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

errors in importing packages.

 
Dushyant Shukla
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Dushyant Shukla
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Steve sir.
The problem is resolved.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic