jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes Setting Classpath of Java in Linux(RedHat-5) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Setting Classpath of Java in Linux(RedHat-5)" Watch "Setting Classpath of Java in Linux(RedHat-5)" New topic

Setting Classpath of Java in Linux(RedHat-5)

Amit K Srivastava

Joined: May 31, 2012
Posts: 7
Hello Sir,

I am trying to run java in RedHat 5.I have installed jdk1.6.0_30 , and set class path as follows:
1- vi ~/.bash_profile
2- Added following lines :

[root@localhost ~]# vi ~/.bash_profile

Then You Get file like this .Now Add following lines .

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc

# User specific environment and startup programs


export PATH

Question: When i am compiling like " javac Hello.java " .It compile file and when " java Hello " . Then it gives some message like "main class not found...." .So i am amazed that same things are working fine at one PC , and when i am trying to run in another PC, so get this error. I am not getting where is problem ?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15002

An error that looks like "main class not found" does not have anything to do with PATH, so that's not the problem.

It's most likely because you have set the CLASSPATH environment variable, or because the *.class file for the class that you have is not on your system or not in the correct directory on your system.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 44590
As a general rule, you should not set a system classpath. You should set a classpath for each application.
Try this:
[campbell@campbell-computer ~]$ echo $CLASSPATH

[campbell@campbell-computer0 ~]$
Note the blank for classpath. If you don’t specify a classpath, the Java runtime will use the “current directory”, also called . as its classpath. That is usually what you want. You would appear to have set a PATH in that bash file, which looks probably incorrect. What you have done is put the path to your wanted Java installation last in the path; if there are any other Java installations on your computer, they will be found first. If you want to use that JDK1.6.0_30 runtime, you would have to put it first in the path.

I think you would have to give us more detalis about the classpath on both those computers, the contents of the directories where those Hello classes are, and whether that Hello class contains a main() method.
I agree. Here's the link: http://aspose.com/file-tools
subject: Setting Classpath of Java in Linux(RedHat-5)
It's not a secret anymore!