Which of these is my JDK path, and which is JAVA_HOME? - java

I just installed Linux Mint and am trying to configure SpringSource Tool Suite which requires you to direct it to the system "JDK path". Although I haven't explicitly downloaded/installed Java on this system yet, when I ran the update manager I did see Open JDK get installed and found several directories under /usr/lib/jvm (see screenshot below). My questions are:
Spring Tool Suite requires you to specify a path to the JDK, and my question is, which one do I choose, and why?; and
How do I tell which of these is my JAVA_HOME?; and
What's the difference between the "JDK path" and JAVA_HOME?
Thanks in advance!
Edit:
echo $PATH --> /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
java -version -> java version "1.7.0_03"
OpenJDK Runtime Environment (IcedTea7 2.1.1pre) (7~u3-2.1.1~pre1-1ubuntu3)
OpenJDK 64-Bit Server VM (build 22.0-b10, mixed mode)
which java -> /usr/bin/java

Spring Tool Suite requires you to specify a path to the JDK, and my question is, which one do I choose, and why?; and
This can only be answered according to the needs of your application. Do you need the stability of Java 6 or the features added in Java 7? Are there APIs you intend to use that are only available in Java 7 or are the Java 6 libraries sufficient? Do you have customers that require the use of one JVM over another? Only you can answer these questions.
How do I tell which of these is my JAVA_HOME?; and
You will want to make JAVA_HOME reference the specific JVM environment that you've decided on for your project. For example, if you decide on Java 6 you'll probably want to set your JAVA_HOME to /usr/lib/jvm/java-6-openjdk-amd64.
What's the difference between the "JDK path" and JAVA_HOME?
The JDK path refers to the Java Development Kit - which includes the java compiler, debugger and other tools associated with developing java programs. JAVA_HOME can reference either the JDK root or the JRE (Java Runtime Environment) root directory when running java programs; but you should, for development purposes, always have JAVA_HOME reference the JDK root.

Related

Cannot use Java 7 installation if Java 8 is installed

I normally still use Java 7 for all my coding projects (it's a company "politics" issue), but I installed Java 8 for one third-party project I am contributing to. Now, it seems I cannot have Java 8 installed in Windows 7 x64, and still use Java 7 by default:
C:\>"%JAVA_HOME%\bin\java.exe" -version
java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode)
C:\>java.exe -version
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)
As you can see, JAVA_HOME is completely ignored.
I also have Java in the path, using "%JAVA_HOME%\bin", which resolve correctly to Java 7 when I check the path in a DOS box, but it still makes no difference.
I checked in the "Java Control Panel" (not sure if this affects the default command-line Java version). Under the "Java" tab, the "View..." button, you get to see "registered" Java versions. I can add all the versions under the "User" tab, but under "System" there is only Java 8, and no way to change it.
Am I missing something, or did Oracle just make it impossible to use Java 7, unless I de-install Java 8? I don't want to have to specify the "source" and "target" everywhere, and I don't even know if it is possible for me to specify it everywhere, where Java is used.
EDIT: What I did is I de-installed all Java. Then installed the latest Java7 (both 86 and x64), and then the latest Java8 (both 86 and x64). After I did that, I noticed that the x64 JDK was gone. It seems Java8 killed it. So I re-installed the JDK 7 x64, after the JDK 8 x64. Still, JDK7 x64 did not seem to "replace" the "java.exe" which is copied into the "Windows" directory itself (I assume THAT is the problem).
When you install jdk8 it adds an entry like this
C:\ProgramData\Oracle\Java\javapath
to beginning of your PATH environment variable, removing this entry should resolve your problem.
You can select the JRE version from the command line with the -version: option.
> java -version:"1.7" MyClass
should select the 1.7 JRE if installed properly.
The list of the properly installed JRE is in the registry, see the key :
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment (32bit)
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft\Java Runtime Environment (64bit)
You can set the "CurrentVersion" there if you want a different default version than the latest.
See http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html#options
Don't modify your PATH to point to a particuliar JRE, let the special java.exe in Windows/system32 do the job.
Windows and Unix both find programs using their PATH environment variable. You have an java.exe in your Windows\System32 which is appearing before your "preferred" version of Java.
Change the PATH to be the one you need, or specify the full path when you need a different version.
2 Steps
1
Change registry key **HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\CurrentVersion** to point to 1.7
2
Copy java.exe,javaw.exe and javaws.exe from your java 1.7 version to Windows\System32 folder
(Since the corresponding files of java 1.8 are already there, you might have to overwrite with admin permissions)
3
(OOps actually not required 3rd step )
Open a new cmd window and check
java -version
Looks like you have to check where in your PATH is located your JAVA_HOME variable, the PATH is evaluated from left to right. A tip for you is to do all your Java system variables configuration at the beginning of your PATH.
PATH = %M2_HOME%\bin;%JAVA_HOME%\bin;C:\ProgramData\Oracle\Java\javapath;...
Probably that's why after doing this:
- java -version
you are getting this:
- java version "1.8.0_05"
because there are other areas in your PATH that are pointing to other java.exe, for example C:\Windows\System32 or C:\ProgramData\Oracle\Java\javapath etc.
I had to make 2 changes for it to work:
Changed the Registry key 'Software\JavaSoft\Java Runtime Environment'\CurrentVersion' to 1.7 from 1.8
The Java 8 installation adds a new entry to the PATH environment variable 'C:\ProgramData\Oracle\Java\javapath'. I removed this entry from the PATH.

Confusion about Java Versions

So I'm trying to get the latest version of Java. When I run:
java -version
I get:
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)
When I run:
javac -version
I get:
javac 1.6.0_65
Now I've just downloaded and installed JDK 8. When I go into System Preferences --> Java --> Update, I see:
Your system has the recommended vesion of Java.
Java 8 Update 05.
I guess I have a few questions:
1) Don't I want the JDK and my version of Java to match up?
2) Why does my Java Control Panel claim I have Java 8, but my work in the terminal (when checking my Java version) says otherwise?
Thanks for the help,
Mariogs
The probably "simple" answer is you have two versions of java installed. On the command line you currently use 1.6. Thus the old one is active. In system preferences you see the version of java 8.
Windows:
You can change the version of the command line to java 8. Set PATH environment variable and JAVA_HOME or via windows preferences. I recommend the first one.
Mac: /usr/libexec/java_home is the starting point for switching java versions on the command line. Check out this post to understand how to handle different java versions on the Mac. IMHO this answer is a good solution.
The Java Platform offers both the JRE and the JDK in order for users to run Java programs. The JRE stands for the Java Runtime Environment, and the JDK stands for the Java Development Kit.
The JDK is meant for Java developers - that is, those who build applications/write programs in Java. It contains tools that are needed for Java coding, including -javac to compile programs.
The JRE is meant for regular users - those who only need to run Java programs on their computer and are not interested in development.
The reason for the discrepancy in your case is because you're looking at the JRE and JDK and trying to compare the two. The current JDK that you have is Java 8, whereas the current JRE that you have is 1.6.0_65. It is problematic that your JRE version does not match your JDK version, but without your PATH variable or other information about your install, we can't help you fix your installation.
1) Yes, if you use the JDK at all, you want the JRE (runtime environment) to come from the JDK (development environment) (a JDK necessarily includes a JRE).
2) Likely your path variable is set so that you invoke Java from your Java 6 installation; you need to find the equivalent for your Java 8 installation and set the path for that. Without information about your operating system, we can't help you do that.
We should know the reason for this
Our OS comes with a predefined (built-in)set of tools and utilities. When we try to execute the command e.g. cls in the Windows command line then it is already present in system path variable and os will refer the corresponding binary of cls to execute the command.
However, when we install any third party tool/software then path variable is not updated accordingly.
When we install different versions of java on your system then installations go to different directories. E.g. JDK installation directory for Windows will be
C:\Program Files\Java\jdk1.8.0_161
Similarly, JRE installation directory for Windows will be JDK installation directory for Windows will be
C:\Program Files\Java\jre1.8.0_161
We need to update the path variable of OS to point to the appropriate directory. If we set the path of JDK then it will execute a binary from JDK bin directory.
Solution
we need to update JDK or JRE version specific directory location into PATH Environment variable.
Let me see if I can clear it up for you.
1)Yes, arguably you nearly want this to be true.
2)It could be few things, but most likely that a previous instillation was not properly removed. So one gets called instead of the other.

Switch between 32-bit and 64-bit JDK platform on Windows 7

I am using Windows 7 on my laptop. I am working with jpcap libraries which work only on 32-bit JDK. Having both 32 and 64 bit JDKs installed on my machine. How can I switch between 64-bit and 32-bit JDK?
I tried changing the %JAVAHOME% and %PATH% environment variables, but it didn't work. Should I change anything in the registry?
#Srikant Sahay, Thank you very much! It did work on widnows 8.1 64 bit OS.
I am able to Switch between 32-bit and 64-bit JDK platform on Windows 8.1 on demand. The trick, as Srikant suggested, is to set the path before all other path variables. Make sure you put fist in the path variable.
java -d32 -version ( or simply )
java -version
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)
However, only one instance works at a time. Either you choose the 32 bit version or the 64 bit version. So, if you type "java -d64 -version" you will get
Error: This Java instance does not support a 64-bit JVM.
Please install the desired version.
Therefore, if you instead want a 64bit JVM you should put the JDk installation folder(in my case "C:\Program Files\Java\jdk1.7.0_51\bin" since the OS is 64 bit by default) first in the path variable.
cheers!
You can either set your path, or switch between JDK's in your IDE. Personally I use JetBrains IntelliJ IDEA and set the JDK via the IDE.
Setting via IDE:
From within a project:
click File -> Project Structure
Select Project under Project Settings
Select the Project SDK. If yours is not listed, click New -> JDK and browse for the JDK
From a new project:
Click File -> New Project
Select the Project SDK. If yours is not listed, click New -> JDK and browse for the JDK
If you want to set your path:
Follow the directions listed on the java.com site.
Keep in mind that your jar will run using whatever version of java is specified in your PATH.
If your PATH variable is not working, try cleaning up your path variable by removing unnecessary entries and rebooting. After reboot add Java to the path and reboot again.
If your still having issues, try executing using the absolute path of the java version your trying to use to ensure it works. If it does work, check your path variable against it to ensure it is accurate.
No, don't touch the registry. Each running Java application gets a single unique JVM instance. So a single java program cannot run some parts of the code in one JVM and other parts of the code in another JVM, as far as I know. You can, however, choose which JRE a particular java program runs in, so you can run the entire jpcap program in your 32 bit java version. Use a startup script (batch file) that points to the exact location of java.exe. When you run "java MyClassName" it's really just finding the java executable on the PATH environment variable, so by explicitly specifying your path, you get to choose your version. In other words, if you run a java program using "java MyClassName" (or if a program on your machine does so) it will use the java.exe application found on your PATH environment variable. Applications themselves can use whatever environment variables they choose: typically the ones used for java are JAVA_HOME and JRE_HOME. So you might want to try setting both of those and then trying to run your program again.
Set the path of your java in System Environment Variables PATH variable. Set it to be before any other path (even System 32 if java or javaw is present there).

Install JRE if not installed

I've been looking, on the web and this forum, for the correct way to include the Java Runtime Environment with my Java application.
I know that the JRE is machine-dependant and thus, the JRE to provide with my application will change if I want to deploy for MAC or Linux for example.
What I really want to know (assuming what I said before is correct), is :
"Is there a way to check whether a JRE is installed on the client machine, and if not install it before trying to run my application ?"
Because I do not think it is possible :
Do you think I should deploy my application with the JRE folder adapted to the client system, and launch my application with a script using the java.exe contained in the JRE folder ?
This avoids installing any Java stuff, but it doesn't look like a good practice to me...
If your application is client-side, I would offer both options: installation with and w/o JRE. Many java applications offers both installations. For example, SmartGit application allows you to download installation with bundled JRE or one that uses existing JRE (where its users responsibility to have the compatible version of java). Many application servers comes with their own JDK already included with the installation.
So, bundling deployment with your JRE is fine if you don't want any trouble with your customers; however, I would allow non-JRE installation as well (to satisfy picky ones :).
If your application is server-side, usually it doesn't come with JRE, but again, this is not a rule.
Moreover, your running/installation script may check if correct JRE or JDK is installed (by checking if the JAVA_HOME is set etc) and then exit if JRE is missing. Even more, the script can even download java and install it locally - although it would be more practical to just use bundled JRE that you have prepared with the application. Or, if JRE is detected, you may ask user if they want to use existing java or bundled.
Bundling JRE is not a big deal. Even I sometimes install java application with bundled JRE, because I switched on my system to e.g. new version or 64-bit version of java that is not supported by application and so on...
Hope this helps ;)
java -version command on CMD of windows tells JVM version; so you can decide if you need to install or not based on the output of this command.
C:\Users\501200I958>java -version
java version "1.7.0_17"
Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

Installing JDK and setting JAVA_HOME

What exactly is the purpose of JDK - running java programs or developing?
There seems to be too many packages that include java and jdk/sdk in their title. Which one should I install if I want to develop Java applications?
Who uses JAVA_HOME and what should I set it to be?
JDK is development environment. JVM is runtime environment.
You should download java installer from oracle web site or install it from repositiry manager
JAVA_HOME system variable usually is required for enterprice java software (application servers, DBs, development tools and so on). You should set JAVA_HOME variable to root directory of JDK or JVM(setting it to JDK always works, but maybe some software will run as expected with JAVA_HOME pointing to JRE). If you set JAVA_HOME right then $JAVA_HOME/bin/java -version command should pring version of java.
JRE means Java Runtime Environment. Most Java Software only needs a JRE to run.
JDK means Java Development Kit. A JDK allways includes a JRE. If you develop you most certainly allways use the JDK, since it contains source and docs of java's own Classes.
Also there is software (usually software for development) that uses tools of the JDK to run, e.g. this software needs the JDK as runtime environment (for example: ant).
JVM means Java Virtual Machine and is the program that runs your java program no matter if in JRE or JDK.
JAVA_HOME is the path to the JDK
JRE_HOME is the path to the JRE
JDK - Java Development Kit (in contrast to JRE - Java Runtime Environment).
If you don't know which version of Java you need, just get the latest (currently Java Platform (JDK) 7u5). Unless you already have a development tool, you might want the Netbeans bundle instead.
JAVA_HOME is used by some software that depends on Java - ant, which is a build tool, is one that comes to mind. It should be set to the directory which contains the bin directory, which in turn contains the java executables.

Categories