Reputation: 35
I have created a package in c:\world and I want to import it to my java source file stored in d:\java. It says that unable to access the package c:\world\Balance.class. What do i need to do??
Upvotes: 1
Views: 3916
Reputation: 59607
You'll need to have the location of the imported classes on your classpath when compiling your classes and running your code.
From your description and comment, it sounds like you have a package named world
with a class named Balance
, with Balance.class
in c:\world. This should work from d:\java:
javac -cp %CLASSPATH%;c:\ SomeClass.java
Replace SomeClass.java
with the name (one or more) of the classes that you're trying to compile in d:\java.
You'll also need to have c:\ in the classpath when you run your code.
Upvotes: 2
Reputation: 85779
You have 2 ways to solve this problem:
Make the packages available in a single project, this means, both packages would be in the same source directory.
Make a jar that contains your world
package. Copy this jar to your lib folder in your project and add it to the classpath, now the world.Balance
class can be reached in your current project.
Upvotes: -1
Reputation: 6947
If you are seeing what I think you are seeing (no c:\world
in the specific error message), then it's easy. You need to add c:\world
to your CLASSPATH setting.
After that, a simple import Balance
(or whatever) should suffice.
Otherwise, a MWE (Minimal Working Example) illustrating the issue, and the exact error message you are getting, would be helpful.
Upvotes: 0