File Location Problem

hello this is only a newbie question.

I have organized my java file into a folder and sub folder

e.g.

c:\proj\main.java

c:\proj\frame\frmMain.java

when i compile main.java it doesn't detect frmMain.java

how to specify the location of frmMain.java because in c\c++

you just put #include c:\proj\frame\sample.c but i can't use

import c:\proj\frame\frmMain.java.

Thanks guys.

[435 byte] By [Ryan747a] at [2007-11-27 11:45:57]
# 1

in ur frmMain.java put this at the top

package frame;

in your main.java ..

use this

import frame.frmMain

( Assuming the name of your class is frmMain )

smithdale87a at 2007-7-29 18:04:47 > top of Java-index,Java Essentials,New To Java...
# 2

you have to add that path to the class path.

go into the command prompt.

(cd) go into the program folder.

cd c:\proj

java -cp .;frame main

voila.

or alternately from anywhere:

java -cp "c:\proj";"c:\proj\frame" main

(the quotes are only necessary if you have a space in the path)

[edit: or as smithdale mentioned you can add it as a

package]

TuringPesta at 2007-7-29 18:04:47 > top of Java-index,Java Essentials,New To Java...
# 3

@TuringPest

if ever I have many sub folders, so I have to add each sub folders to the class path?

e.g.

java -cp "c:\proj";"c:\proj\folder1" main

java -cp "c:\proj";"c:\proj\folder2" main

etc...

Ryan747a at 2007-7-29 18:04:47 > top of Java-index,Java Essentials,New To Java...
# 4

@smithdale87

if also I have many sub folders i have to import each one of them?

e.g.

import folder1.hello

import folder2.hello

Ryan747a at 2007-7-29 18:04:47 > top of Java-index,Java Essentials,New To Java...
# 5

If you use packages (like you are supposed to!) then you DONT

have to do that. you can just compile regularly from the package

root.

But for small little things and for the sake of learning you should be

aware of the classpath solution.

But yes, if you are not using packages you have to include EVERY

folder.

java -cp .;folder1;folder2 main

TuringPesta at 2007-7-29 18:04:47 > top of Java-index,Java Essentials,New To Java...
# 6

setting the classpath is much easier.

thanks for all your help.

Ryan747

Ryan747a at 2007-7-29 18:04:47 > top of Java-index,Java Essentials,New To Java...
# 7

Yea but it really is a BAD habit.

Please trust a person who has had that habit for

WAY too long. It took me forever to break it.

TuringPesta at 2007-7-29 18:04:47 > top of Java-index,Java Essentials,New To Java...