Working with some basic java apps on CentOS 5 linux and I have my classpath
set to point to home/pathToJava/bin
which contains javac
and java
and I have .java
files in home/pathToFolderA/src
and home/pathToFolderB/gen-java
When I run javac
and java
in home/pathToFolderA/src
everything works perfectly
But when I run javac
from within home/pathToFolderB/gen-java
on fileName.java
I get a file not found error, specifically
javac: file Not found: fileName.java
Usage: javac <options> <source files>
Why could this be happening?
Thanks for all help
You shouldn't set your classpath to point to your JDK bin directory -- instead it should be the PATH environment variable, which serves a different purpose to classpath. (The classpath defines a list of jars and directories containing compiled Java .class code; the PATH variable defines a list of paths where the shell needs to look and locate programs to execute when they are not found in the current directory -- so if you type for instance zip
-- it would look in all the directories defined in PATH
and figure out that zip
program is located under /usr/bin
)
Secondly if you want to compile sources from both directory you need to specify:
home/pathToFolderA/src
and home/pathToFolderB/gen-java
)To sum it up, it would be something like this to compile:
javac -d /home/pathToFolderWithResultsOfCompilation -classpath /path/to/some.jar:/path/to/another.jar home/pathToFolderA/src/*.java home/pathToFolderB/gen-java/*.java
and to run your compiled programs:
java -classpath /path/to/some.jar:/path/to/another.jar:/home/pathToFolderWithResultsOfCompilation full.name.of.your.Java