Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting Classpath of Java in Linux(RedHat-5)  RSS feed

Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 " .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 ?
Java Cowboy
Posts: 16079
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Posts: 57446
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Hey, sticks and stones baby. And maybe a wee mention of my stuff:
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!