Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds


  Asked By: Kaua    Date: Jul 15    Category: Java    Views: 2811

I have a few questions, What are the
CLASSPATH and PATH enviroment variables in Linux and is
there a difference between the two. I have
downloaded Java 2 SDK version 1.3.1_02 rpm file and
installed it on a Wintel machine running RedHat 7.1. I got
a message confirming it was installed. However,
when I try to compile a test file from the command
line "javac Test.java" I get the message "bash: javac:
command not found. Any suggestions? I also
installed Forte for Linux on the same machine and it works
fine as long as I use the switch -jdkhome statement to
start the program "runide -jdkhome
/usr/java/jdk1.3.1_02". I can compile with no problems. However, I will
soon be removing resources from this machine and it
will no longer have enough memory to run Forte. I
suspect a classpath problem but I am not sure. From the
Sun web site instructions, I used this command to set
my classpath, export



7 Answers Found

Answer #1    Answered By: Jackson Williams     Answered On: Jul 15

The first error indicates, that bash can't find
the executable javac. Did you check whether javac  is
in your bash path? (try the command<br>echo $PATH
<br>and check if one of the path  entries is your java/bin
directory.<br><br>Later you might discover, that under unix the classpath
entries are separated by : instead of ; as in M$

Answer #2    Answered By: Ethan Evans     Answered On: Jul 15

The path  suggestion worked great! I set the PATH
using "export PATH=$PATH:/usr/java/jdk1.3.1_02/bin" and
it compiled without problems. However, when I ran
the command  "java Test.class" and I get the dreaded
"exception in thread "main" java.lang.NoClassDefFoundError:
Test/class. Must be a classpath  problem. Any

Answer #3    Answered By: Komal Mohammad     Answered On: Jul 15

unless you made a typo, you compile  a java  source
file using: javac  sourcefile.class (notice the 'c' at
the end of 'java_';<br>when you want to run  the class
file: use java classfilename(the same as source)
'without an extension!' <br>Don't forget! However you
spelled the "PUBLIC CLASS 'filename' " inside of your
code, you MUST use the same to compile the program  or
you will get an error! so, myprogram is not the same
as Myprogram! <br><br>This may seem rather trivial
to you, but there are always beginners that read
this information and are unaware of the above
information about java.

Answer #4    Answered By: Chau Tran     Answered On: Jul 15

also as a vague memory, there is a file  in linux
that you can use to set the path  the same as ms users
set their path. it's been awhile since i've used
linux, but try looking up the config files in your
usr\bin or somewhere like that. Once you find it and set
it, you can compile  and run  a java  file from
pratically any directory.

Answer #5    Answered By: Viheke Fischer     Answered On: Jul 15

The environment setting is usually done in Unix'
.profile file  and Linux has a similar file for both the
system and the user. <br><br>Do a find / -name
"*profile*" -print <br>from a high level directory (your home
or root) to find all of these files.

Answer #6    Answered By: Jeanette Greene     Answered On: Jul 15

Actually, The easiest way to do it is one
of the two ways, If your system hosts a
number of users, and you want all users to have access
to it in their path, add it to: /etc/bashrc or
/etc/profile It doesn't matter which, however if you use bash,
and so does everyone else I would suggest placing it
in /etc/bashrc since I believe it is executed
last. If its only one user, you can add it to ~/.profile
or ~/.bashrc Note, you can execute vi
~/.bashrc or vi ~/.profile and it will work for whatever
user you are logged in as. Or, que prefere, edit
/homedirectoryofuser/.bashrc or /homedirectoryofuser/.profile One more
minor note, ~ equates to the home directory of whatever
user you are logged in as, (at least in

Didn't find what you were looking for? Find more on Linux Java PATH and CLASSPATH Or get search suggestion and latest updates.