Problems when compiling in command line.

Works fine in eclipse, but when I compile in command line terminal, I get errors.

These are the lines it has a problem with:

================================

KeyStrokeListener mListener = new KeyStrokeListener(this);

Thread mListenThread = new Thread(mListener);

================================

This is the full error:

==================================

Player.java:6: cannot find symbol

symbol : class KeyStrokeListener

location: class ver0.Player

KeyStrokeListener mListener = new KeyStrokeListener(this);

^

Player.java:6: cannot find symbol

symbol : class KeyStrokeListener

location: class ver0.Player

KeyStrokeListener mListener = new KeyStrokeListener(this);

^

2 errors

=============================

I think it's not finding the other class (even though it's in the same folder). If you want me to elaborate, I will. But, I think the solution is probably just something small.

[1011 byte] By [zensunnia] at [2007-11-26 18:59:07]
# 1
Add current directory into your classpath.
Vishwas_Prasannaa at 2007-7-9 20:40:13 > top of Java-index,Java Essentials,New To Java...
# 2
Sorry, through a command, or in the code?I typed in "javac -classpath /home/kirk/workspace/myGame/ver0/", but it gave me this:javac: no source filesUsage: javac <options> <source files>use -help for a list of possible options
zensunnia at 2007-7-9 20:40:13 > top of Java-index,Java Essentials,New To Java...
# 3

Through command line add '.' ( current directory) to CLASS_PATH environment variable.

Just check this example...

JavacTest

Package1

Pck1.java uses Pck2.java

Package2

Pck2.java uses Pck1.java

to compile from JavaTest directory

d:/JavacTest/ javac -classpath . Package2/Pck2.java

will compile Pck2.java and Pck1.java

Message was edited by: Vishwas

Vishwas_Prasanna

Vishwas_Prasannaa at 2007-7-9 20:40:13 > top of Java-index,Java Essentials,New To Java...
# 4
ops double post*
zensunnia at 2007-7-9 20:40:13 > top of Java-index,Java Essentials,New To Java...
# 5

> Sorry, through a command, or in the code?

>

> I typed in "javac -classpath

> /home/kirk/workspace/myGame/ver0/", but it gave me

> this:

>

> javac: no source files

> Usage: javac <options> <source files>

> use -help for a list of possible options

you miss the extensions *.java

javac -classpath /home/kirk/workspace/myGame/ver0/*.java"

p_epia at 2007-7-9 20:40:13 > top of Java-index,Java Essentials,New To Java...
# 6

I think there might be something else that's messing it up....

I've tried:

javac -classpath /home/kirk/workspace/myGame/ver0/*.java with the same error.

and

javac /home/kirk/workspace/myGame/ver0/*.java

I mean, all the files are in the same folder. Isn't that the first place the compiler looks? I dunno what gives.

zensunnia at 2007-7-9 20:40:13 > top of Java-index,Java Essentials,New To Java...
# 7

> I think there might be something else that's messing

> it up....

> I've tried:

>

> javac -classpath /home/kirk/workspace/myGame/ver0/*.java with the same

> error.

That's because it's wrong.

You must specify the compiler on the command line, and the file to compile.

If you use the -classpath option, you must also provide an argument to that option. That means there would be four separate tokens on the command line. (not 3)

For example:

javac -classpath . MyProgram.java

> and

> javac /home/kirk/workspace/myGame/ver0/*.java

>

> I mean, all the files are in the same folder. Isn't

> that the first place the compiler looks?

Not if the classpath overrides that for some reason. So if you have a classpath environment variable set, that could confuse things, and you'd have to either change the env var or use the -classpath option to the compiler.

Also when you say "in the same folder" -- do you mean in that directory or in subdirectories, or do you mean in that directory and not in any subdirectories?

paulcwa at 2007-7-9 20:40:13 > top of Java-index,Java Essentials,New To Java...
# 8
Also what directory are you in when you run the compiler?
paulcwa at 2007-7-9 20:40:13 > top of Java-index,Java Essentials,New To Java...
# 9
Hi,I think you are using windows operating system.you can try the following command too:set CLASSPATH=%CLASSPATH%;.press enter..
KrisDaSworda at 2007-7-9 20:40:13 > top of Java-index,Java Essentials,New To Java...
# 10

Sorry for taking this long to clarity everything...

Ok, in eclipse, this is my setup:

+myGame //project folder

--default package //Has some stuff in it, but isn't used by anything in ver0 package.

++ver0

KeyStrokeListener.java (uses Player.java)

Player.java (uses KeyStrokeListener.java)

the folder tree is this:

/home/kirk/workspace/myGame/ver0 // ver0 is the only package and contains KeyStrokeListener.java and Player.java

"Also when you say "in the same folder" -- do you mean in that directory or in subdirectories, or do you mean in that directory and not in any subdirectories?"

All the files are in /home/kirk/workspace/myGame/ver0.

So, like this:

/home/kirk/workspace/myGame/ver0/Player.java

/home/kirk/workspace/myGame/ver0/KeyStrokeListener.java

When I am compiling, I am in "/home/kirk/workspace/myGame/ver0" directory. So, when I type ".", I'm really saying "/home/kirk/workspace/myGame/ver0".

I typed "javac -classpath . Player.java" while I was in "/home/kirk/workspace/myGame/ver0" dir on the command line and no luck.

Even tried "javac -classpath . *.java" in "/home/kirk/workspace/myGame/ver0" dir.

Also, i'm on linux. ...and is there a way to turn environment variables classpath off entirely? I think there's two instances of it in linux: CLASS_PATH and classpath.

zensunnia at 2007-7-9 20:40:13 > top of Java-index,Java Essentials,New To Java...
# 11

> When I am compiling, I am in

> "/home/kirk/workspace/myGame/ver0" directory. So,

> when I type ".", I'm really saying

> "/home/kirk/workspace/myGame/ver0".

There's your problem. Keep in mind that the classpath says where the roots of package hierarchies are. So If you're looking for a class in the ver0 package, and the classpath is ".", then it's going to look in a subdirectory ./ver0. If you're already in ver0, then the class can't be found.

Try moving up a directory and doing

javac ver0/*.java

or if that doesnt' work

javac -classpath . ver0/*java

If you really want to compile while you're in the ver0 directory, this may work:

javac -classpath ..*.java

That tells the compiler to start in the parent directory, and if it finds a reference to a ver0 package, look for a subdirectory named "ver0" (that is, your current directory) and find the file there.

> Also, i'm on linux. ...and is there a way to turn

> environment variables classpath off entirely? I think

> there's two instances of it in linux: CLASS_PATH and

> classpath.

I'm pretty sure those are misspelled and thus will be ignored by the compiler. But you can un-define them in your current shell. I believe you can do that by setting them to null, or maybe there's an undef command. Do "man bash" on linux to get the shell help page.

By the way, if "ver0" means "version 0" -- I'd recommend against using the package structure for versioning. You could still have a ver0 directory, but just don't include it in the package structure. It'll make every code update into a package move, which will be a pain.

paulcwa at 2007-7-9 20:40:13 > top of Java-index,Java Essentials,New To Java...
# 12

Thanks a lot.

It's nice when someone takes the time to explain the situation thourougly. I've gone through so many tutorials and forum posts that say nothing of this. In fact, I know like 3 other posts with this same problem.

And thanks for the versioning tip and clearing up the bash script. I got a few tutorials on classpath in the bash script in my google searches, but didn't know what it was trying to accomplish.

I can compile again :)

BTW, when you say I should have a ver0 directory, but not ver0 package, does that mean I can put folders ver0, ver1, ver2 all into one package, and the compiler will find it if the classpath is in the project root folder? (In my case, the root folder would be "myGame", and then the subdirectory would be "<package name>", then inside of the package directory, I would have ver0, ver1 and ver2.)

Or, would that confuse the compiler, since there would be more than one copy of the same class, since ver0 and ver1 both have the same classes?

zensunnia at 2007-7-9 20:40:13 > top of Java-index,Java Essentials,New To Java...
# 13

Well, if you're doing versioning with any real depth, you should start using a source code control tool, such as CVS.

But if you were doing it with directories, I'd suggest something like:

~/myGame <- project folder

myGame/ver0/<- first version

myGame/ver1/<- second version

myGame/ver1/npcs/ <- a package in ver1 of the project

Then when you compile and run you could point the classpath to the version you're using:

javac -classpath ~/myGame/ver1 *.java

I guess.

I suppose, if you wanted to be adventurous, you could try putting multiple versions on the classpath:

javac -classpath ~/myGame/ver1:~/myGame/ver0 *.java

but that would probably break if you've made non-trivial changes between versions. It might be an OK thing to do for bug fixes though.

paulcwa at 2007-7-9 20:40:13 > top of Java-index,Java Essentials,New To Java...
# 14
Actually, the first suggestion makes a lot more sense. That's probably what I'll start doing from now on. When I'm feeling adventurous, I'll start using cvs for version control.
zensunnia at 2007-7-9 20:40:13 > top of Java-index,Java Essentials,New To Java...