Find the answer to your Linux question:
Results 1 to 6 of 6
Hi !I am unable to run a java programe .I am able to compile it easily but when running as java name it shows an error bash: java: command not ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jan 2007
    Posts
    9

    Problem in running JAVA program


    Hi !I am unable to run a java programe .I am able to compile it easily but when running as java name it shows an error
    bash: java: command not found
    Please help me out to find the solution.

  2. #2
    Linux Engineer Zelmo's Avatar
    Join Date
    Jan 2006
    Location
    Riverton, UT, USA
    Posts
    1,001
    It looks like the java binary isn't in your path. What do you get from a "whereis" command?
    Code:
    whereis java
    Stand up and be counted as a Linux user!

  3. #3
    Just Joined!
    Join Date
    Jan 2007
    Posts
    9
    Using the command I get
    /usr/share/java /usr/share/man/man1/java.1.gz
    So how can run my programs?AS I am able to compile.

  4. #4
    Linux Engineer Zelmo's Avatar
    Join Date
    Jan 2006
    Location
    Riverton, UT, USA
    Posts
    1,001
    It sounds like javac is in your path, while java isn't. That's a strange situation, and you can confirm it using a few more commands:
    Code:
    whereis javac
    locate -r "/bin/javac$"
    locate -r "/bin/java$"
    The first command will tell you where the system is finding the java compiler (plus the man page and source directory, if installed). The output you got from "whereis java" just shows the source directory and man page, so either the java executable isn't installed, or it's not in your path.

    The second command will tell you the locations of all java compilers on the system (assuming they're named "javac" and are in a "bin" directory). One of these should match a part of the "whereis javac" output. There should be a java binary in the same directory as javac; if you can't find one there, look in another directory that contains javac (as shown by the locate command).

    If you still can't find a java binary in any of those directories, the third command will show you where any java binaries are located on your system. You can use any of those to run your java bytecode by typing out the full path name to the java executable (including java itself). To add it to your path, put the following line in your .bashrc
    Code:
    export PATH="/path/to/java/bin/directory:$PATH"
    Of course, use the real java bin directory that you found earlier.
    Stand up and be counted as a Linux user!

  5. #5
    Just Joined!
    Join Date
    Jan 2007
    Posts
    9

    Unhappy

    I am still not able to run the programs.I got following output while using the commands
    1>whereis javac
    javac: /usr/bin/javac /usr/X11R6/bin/javac /usr/bin/X11/javac /usr/share/man/man1/javac.1.gz
    2>locate -r "/bin/javac$"
    /usr/bin/javac
    /usr/lib/j2se1.4-sun/bin/javac
    3> locate -r "/bin/java$"
    /usr/lib/j2se1.4-sun/bin/java
    /usr/lib/j2se1.4-sun/jre/bin/java
    /usr/lib/jvm/java-1.5.0-sun-1.5.0.10/bin/java
    /usr/lib/jvm/java-1.5.0-sun-1.5.0.10/jre/bin/java

    Still I am not getting how to correct the path.Please help me out
    Thanking you.

  6. #6
    Linux Engineer Zelmo's Avatar
    Join Date
    Jan 2006
    Location
    Riverton, UT, USA
    Posts
    1,001
    It looks like you have GNU's GCJ, as indicated by /usr/bin/javac, but not GNU's JRE. You have both the 1.4 and 1.5 versions of Sun's official Java runtime in /usr/lib. Assuming you want to use the more recent one, add this line to your .bashrc
    Code:
    export PATH+="/usr/lib/jvm/java-1.5.0-sun-1.5.0.10/bin"
    To apply the change right away, source the bash config file:
    Code:
    source ~/.bashrc
    Stand up and be counted as a Linux user!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •