This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting Classpath of Java in Linux(RedHat-5)

 
Amit K Srivastava
Greenhorn
Posts: 7
  • 0
  • 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
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin
PATH=$PATH:/opt/jdk1.6.0_30/bin

export PATH
unset USERNAME

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
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • 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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47258
52
  • 0
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic