We help IT Professionals succeed at work.

import problem

jtcy
jtcy asked
on
177 Views
Last Modified: 2012-06-08
Very easy question. Can someone tell me how to import a class which resides in a folder outside current folder?

i have a Abc.java in abc folder, and i want to import cde.java which resides in cde folder, and cde folder and abc folder both resides in def folder.

Comment
Watch Question

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
If you are using Eclipse IDE (might be possible with all the IDE's), there you have refactoring choice.

You can use that refactor to move / rename your package, class-name, method name and what not.
Mayank SPrincipal Technologist
CERTIFIED EXPERT

Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
is there anyway that i don have to edit the classpath?
By the way, by using ECLIPSE or JBuilder the importing is made easier as
these tools give you an invisible CLASSPATH.

;JOOP!
Mayank SPrincipal Technologist
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
OOPS!  Misunderstood the question!

if abc and cde folders are within def folder.

Then you have to give the classpath till def folder.

No other way!
Mayank SPrincipal Technologist
CERTIFIED EXPERT

Commented:
>> Posted in your other question.

That was for:

>> is there anyway that i don have to edit the classpath?
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
hm..ok thanks guys
Mayank SPrincipal Technologist
CERTIFIED EXPERT

Commented:
By the way, why a C :-(

A C grade is given if the answer is not good, not if the question is easy.
Did we solve your problems? Can you work now?

;JOOP!

Author

Commented:
hm....donno...i don think the lecturer would want us to..change classpath or smth.

we are told to write two classes, one in seperate directory. each labelled with its own folder name as package. just as what i had described above, a folder includes a.java, b folder includes b.java, both folders resides in x folder. i wan to have b import a.java, but find no way to do that. i don think the lecturer would want us to change the classpath, if so, they would have to change classpath for every student's to mark.
I think the lecturer expects every student to find out that he/she must set CLASSPATH for himself
as you probably must do for the rest of your life.

Then again: full pathname!


;JOOP!
Mayank SPrincipal Technologist
CERTIFIED EXPERT

Commented:
Class-path is the correct way to do it. Don't *think* what the lecturer might want or might not want. Just do whatever he wants in the way it is to be done.
Mayank SPrincipal Technologist
CERTIFIED EXPERT

Commented:
>> i don think the lecturer would want us to change the classpath

Impossible.

Author

Commented:
ok, how to change the classpath?
i went to environment variable there, adding the full folder path to the path variable, but...not working
Mayank SPrincipal Technologist
CERTIFIED EXPERT

Commented:
Have you visited your other question:

https://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_20940990.html

?? You can also set it from the command prompt. When you add the folder path, add only till the parent folder of abc and cde (i.e., only till the dce folder).
Mayank SPrincipal Technologist
CERTIFIED EXPERT

Commented:
>> adding the full folder path to the path variable

Add it to the classpath variable, not the path. If it is not there, then make a new one.

Author

Commented:
>>?? You can also set it from the command prompt. When you add the folder path, add only till the parent folder of abc and >>cde (i.e., only till the dce folder).


Cool, it works now. thank you.

Author

Commented:
can I ask how to set the classpath back to original. i mean....if i wan to get rid of that from classpath
Mayank SPrincipal Technologist
CERTIFIED EXPERT

Commented:
First of all - this question is closed. So we'd better discuss it in the other question you opened at:

https://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_20940990.html

- you did not need to open two questions for asking the same thing, that too with the same subject! Everytime I receive a mail-notification, I don't know whether it is for this one or that one. Sometimes I miss the other one if there are two.

If you want to delete something from the classpath, you can edit it always. set classpath=.... // whatever
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.