java -version resullts -bash: java: command not found (in linux) - java

Java -version in Linux is not seem to be working and returing -bash: java: command not found error,though im able to run java related apps.
I have installed jdk in my new linux machine and i have set the environment variable JAVA_HOME using which i can execute JAVA apps and I can echo the java path i set.
Problem is i can not see the java version i have installed ,using the command java -version (i want to know that everything is set fine)
can someone guide me ,what i am missing here.

You should have your java installation directory added to PATH environment variable in order to use java from terminal. For example:
export PATH=<your java Directory>/bin:$PATH

Related

javac NotRecognized - Java version 1.8.0_161 |

I'm testing out some code on a computer running Windows 8.1.
I'm using the command prompt and I can't seem to get javac (or javaC) to compile my text file. I've added the path as an environment variable (...\bin) and it doesn't do work. java -version and java prints information to the console, just can't get javac to work.
Seems like you are having JRE installed on your machine. You can go to your JAVA_HOME/bin folder, check if javac file is there or not. If not, it means you have JRE installed. You need to install java JDK.
FOr download jdk, this is the url for JDK 8:
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Previous version available here:
http://www.oracle.com/technetwork/java/archive-139210.html

installed java 7 but terminal responds with version 6

So I installed Java 7 and verified that it was installed Java now shows up under System preferences. However when I run java -version it still returns
java version "1.6.0_65
How do i fix this so that my computer points to the correct version? Also, is this a problem in the future if i choose to not fix this?
Thanks
You need to set your java 7 directory bin path to system PATH variable. As you are using Mac OS, use this article to set path correctly:
JAVA HOME in Mac OS
Use the following command to list the installed versions of Java:
/usr/libexec/java_home -V
From the output of the above command, copy the path for the version of Java you want to use.
Open up your ~/.bash_profile or ~/.bashrc file and add/edit the line:
export JAVA_HOME=/Path/copied/from/step/2
In your terminal, reload the the file you edited in the previous step using the corresponding command below:
source ~/.bash_profile
source ~/.bashrc
Now, you should see the the correct version of Java on the command line:
java -version

What is the difference between the JAVA_HOME environment variable and the output of "java -version"

What is the JAVA_HOME environment variable actually? I'm in doubt. What is done by setting it ? And I have also another question that if we have two or more JDK s in the OS, we can set one version's path to set the $JAVA_HOME variable and another version as the running java in the machine which is shown by "java -version" command.As I think in ubuntu, java --version command gives the JRE configured (running java) version of java and JAVA_HOME variable defines which version to use for compiling java programs. Am I correct? What is actually the difference between the jdks referred by these two outputs-
1. echo $JAVA_HOME
2. java -version
Lets start with what the two commands do.
echo $JAVA_HOME
This outputs the value of the JAVA_HOME environment variable. By convention, this environment variable is set (typically in a shell "rc" file) to the base directory of a JRE or JDK installation. However, none of the Oracle or OpenJDK core java tools depend on this. You set JAVA_HOME for the benefit of 3rd-party tools, to tell them which of possibly many JRE or JDK installations on the system to use.
So running echo $JAVA_HOME will typically give the directory for a JRE or JDK. But it might be unset ... or point to missing directory.
java -version
This runs the java command and tells it to output its own version information. Unlike the previous, if your shell can find a (real) java command, the information it outputs is definitive.
But which JRE / JDK does will the java command come from?
Well that is determined by the shell, and how it (in general) finds commands. For all mainstream Unix / Linux / BSD shells, this is controlled by the PATH environment variable. The PATH variable defines a command search path; i.e. a list of directories where the shell looks for commands.
So if PATH is /usr/bin:/bin:/usr/local/bin:/home/joeuser/bin:/usr/java/jre-x.y.z/bin then the shell will look for java in each of those directories in turn. The first one java command that it finds will be the one that is executed. You can find out which one it is by running this command.
which java
But that is not the end of it, because if you are using an OpenJDK Java installation on a typical Linux system, the java command in /usr/bin is actually the first in a chain of symlinks that is managed by the alternatives command. The actual executable is at the other end of the chain.
(The alternatives system is a way to implement a switchable system-wide default for a command or set of commands. Read the manual entry for more details. But note that Oracle Java installers (or RPMs) for Linux don't "grok" the Linux alternatives system ... one of my bugbears!)
Finally, it is common to see something like this in a shell "rc" file:
export JAVA_HOME=/path/to/jre # (or jdk)
export PATH=/bin:$JAVA_HOME/bin:/usr/bin:...
There is nothing magical about this. The $JAVA_HOME is going to be expanded by the shell before it sets the environment variable. Tthe actual PATH value will be:
/bin:/path/to/jre/bin:/usr/bin:...
So in summary:
echo $JAVA_HOME tells you the JRE or JDK that a typical 3rd-party tool will try to use by default.
java -version tells you the JRE or JDK that the java command comes from.
They may be different.
JAVA_HOME is an environment variable that contains the directory where Java is installed (if a few versions of Java are installed - this will point to the default)
java -version is a command that shows which version of Java is installed (and again, the one that's used by default in case a few versions are installed)
Addition: Thanks to Luiggi's comment: if the folder where java is installed is not in the PATH (another environment variable) - running java -version or any other java command will fail!
Its not related to jdk and JRE. java -version it is used by the java which is in /usr/bin/java. In some application is used $JDK_HOME. Both the jdks are same. Or we can define different jdk.
echo $JAVA_HOME
will print the value of environment variable called JAVA_HOME. If it's not set, it will print an empty message. Usually, you set JAVA_HOME to the path of the latest JDK installed in your pc.
java -version
will print the version of the java executable (Java Virtual Machine) that is set in your path, if configured. Otherwise, it will throw an exception on the command line.

Eclipse fails to start via an application launcher

Hi everybody.
The problem: elcipse-3.5.0 (Galileo) spits with an error when I try to launch it by clicking its launcher. The curse sound like this:
A Java Runtime Environment (JRE) or
Java Development Kit (JDK) must be
available in order to run Eclipse. No
Java virtual machine was found after
searching the following locations:
/home/emanemos/bin/eclipses/eclipse-3.5.0/jre/bin/java
java in your current PATH
However, everything goes smoothly when eclipse is started from console.
Before installing eclipse I've installed jdk1.6.0_16. I also created the $JAVA_HOME variable and changed my $PATH:
$ echo $JAVA_HOME
/usr/lib/java/jdk1.6.0_16
$ echo $PATH
/home/emanemos/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/lib/java/jdk1.6.0_16/jre/bin
So that, my terminal got to know what java is:
$ java -version java version
"1.6.0_16" Java(TM) SE Runtime
Environment (build 1.6.0_16-b01)
Java HotSpot(TM) Client VM (build
14.2-b01, mixed mode, sharing)
Then a folder eclipse was extracted from .tar.gz package under the directory ~/bin/eclipses. I changed the folder's name eclipse to eclipse-3.5.0 and changed $PATH again:
$ echo $PATH
/home/emanemos/bin/eclipses/eclipse-3.5.0:/home/emanemos/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/lib/java/jdk1.6.0_16/jre/bin
From this moment I was blessed to launch eclipse from console by the command eclipse.
However, I feel desperate about using the eclipse's application launcher.
Thanks in advance. I would be grateful for any help.
The message says "No Java virtual machine was found after searching the following locations: /Applications/eclipse/Eclipse.app/Contents/MacOS/jre/bin/"
I have solved it creating the folder /Applications/eclipse/Eclipse.app/Contents/MacOS/jre/bin and linking to the command at /usr/bin/java:
ln -s /usr/bin/java /Applications/eclipse/Eclipse.app/Contents/MacOS/jre/bin/java
Add this to eclipse.ini:-
-vm
$Java_home/jdk1.5.0_14/bin/javaw.exe
I could be off, but it looks to me that you don't have JAVA in your path. If you notice, you had to add it via the echo command. However, that only stays for that session of the terminal. You don't permanently affect the system. (I believe that's why you can launch from the terminal, but not via the launcher.)
Do you have the Java JRE actually installed on your system? If not, I would recommend doing that as that should do all the setup that you would need, then try running Eclipse again.
Edit: I noticed you said that you did install the 1.6 JDK. This should have fixed your problem. If Java is not in your path when you first open up your terminal, then that (I believe) is your real problem and you may need to do a reinstall or troubleshoot there.
(Making a big assumption that you're on Linux using X)
If you've installed the Java JRE without logging out and back in to the X session, the environment the session is in won't contain the $JAVA_HOME variable. It may just be a case of logging out and back in in order to get a new X session.
If you want to keep the same session running, you could try it out by pressing Ctrl+Alt+F9 to start another GUI session.
Fazil Baghirzade i solve the this problem
A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Eclipse. No Java virtual machine was found after searching the following locations:
c:\Program Files\Eclipse\jre\bin\javaw.exe 'javaw.exe' in your current path
go to the "C:\Program Files\Java\jdk1.6.0_39" in this folder have "jre" folder copy it and paste the eclipse folder
thats all!!!

"Could not find the main class. Program will exit"

I'm trying to run SQuirreL SQL.
I've downloaded it and installed it, but when I try to run it I get this error message:
Java Virtual Machine Launcher.
Could not find the main class.
Program will exit.
I get the gist of this, but I have not idea how to fix it. Any help?
more info:
I'm on Windows XP pro.
I have java 1.6 installed, and other apps are running OK.
The install ran OK.
I believe I've followed the installation instructions correctly.
To run it, I'm invoking the squirrel-sql.bat file.
Update
This question: "Could not find the main class: XX. Program will exit." gives some background on this error from the point of view of a java developer.
Is Java installed on your computer? Is the path to its bin directory set properly (in other words if you type 'java' from the command line do you get back a list of instructions or do you get something like "java is not recognized as a .....")?
You could try try running squirrel-sql.jar from the command line (from the squirrel sql directory), using:
java -jar squirrel-sql.jar
The classpath is the path that the system will follow when trying to find the classes that you're trying to run. In the batch file you're trying to execute it probably has a variable like CLASSPATH=blah;blah;etc or a java command that looks similar to
java -classpath "c:\directory\lib\squirrel-sql.jar" com.some.squirrel.package.file
If you can find or add that classpath setting, make sure that it includes a path to the squirrel-sql.jar and any other jar files that it may depend on separated by semicolons (or the root /lib directory that may be included with the installation).
Basically you just need to tell java where to find the class files that you're trying to execute. Wikipedia has a more indepth discussion about classpath and can offer you more insight. http://en.wikipedia.org/wiki/Classpath_(Java)
JAVA_HOME variable must be set, to point to the prog files/java/version???/bin
open squirrel-sql.bat file with some text editor and see if the JAVA_HOME variable there is the same as the one in your enviroment variable
change it if it doesn't match....and than run bat file again
Have you followed these instructions:
http://www.squirrelsql.org/#installation
If so, are you running the batch file or the shell script to run it?
Tweaking MB's answer for windows, will get rid of the console window:
start javaw -jar squirrel-sql.jar
The .bat file does not seem to work.
Just double-click on:
squirrel-sql.jar
or type:
java -jar squirrel-sql.jar
in the command-line.
You can place .; in classpath in environmental variables to overcome this problem.
I tried to start SQUirrel 3.1 but I received a message stating "Could not find the main class Files\Rational\ClearQuest\cqjni.jar" I noticed that C:\Program Files\Rational\ClearQuest\cqjni.jar is in my existing classpath as defined by the Windows environment variable, CLASSPATH.
SQUirrel doesn't need my existing classpath, so I updated the SQUirrel bat file, squirrel-sql.bat.
REM SET SQUIRREL_CP=%TMP_CP%;%CLASSPATH%
SET SQUIRREL_CP=%TMP_CP%
It no longer appends my existing classpath to its classpath and runs fine.
I had this problem when I "upgraded" to Windows 7, which is 64-bit. My go to Java JRE is a 64-bit JVM. I had a 32-bit JRE on my machine for my browser, so I set up a system variable:
JRE32=C:\Program Files\Java\jre7
When I run:
"%JRE32\bin\java" -version
I get:
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) Client VM (build 24.51-b03, mixed mode, sharing)
Which is a 32-bit JVM. It would say "Java HotSpot(TM) 64-Bit" otherwise.
I edited the "squirrel-sql.bat" file, REMarking out line 4 and adding line 5 as follows:
(4) rem set "IZPACK_JAVA=%JAVA_HOME%"
(5) set IZPACK_JAVA=%JRE32%
And now everything works, fine and dandy.
I had the same issue with a different application (BI Publisher) because I installed a 32 bit version of this application on a 64 bit version of Windows.
Java Virtual Machine Launcher - could not find the main class
The solution for my case was to tell BI Publisher where to find the x86 version of JRE:

Categories