• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Setting Classpath of Java in Linux(RedHat-5)

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic