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)
Related
This question falls somewhere between Firebase Tools, MacOS and Java. Probably 75% Java, 20% Firebase Tools and 5% MacOS.
Starting with v10.5, firebase-tools started stating that 'Support for Java version <= 10 will be dropped soon in firebase-tools#11. Please upgrade to Java version 11 or above to continue using the emulators.'
I run macOS v11.6.5 on a Macbook Pro from mid-2014. When I go to Java's Downloads page, it recommends Java 'Version 8 Update 331'. Not Java 11.
Information on downloading Java 11 seems to be scarce. Oracle's page of certified configurations includes MacOS 11, but I can't find anywhere obvious where Java 11 can be readily downloaded.
A big part of the problem seems to be the terminology used. If I run java -version, I get:
java version "1.8.0_331"
Java(TM) SE Runtime Environment (build 1.8.0_331-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.331-b09, mixed mode)
Okay, I have build 1.8 of the Java Runtime Environment, aka the JRE if you are a Java enthusiast. That is apparently what is triggering the warning in Firebase Tools.
There is also a Java product out there called 'Java SE 11'. The product itself is ambiguous, but the checksums all say 'SDK'. (A Software Development Kit: a thing that enables developers to develop Java programs. The name doesn't imply a Runtime Environment: a thing that enables Java to run on an operating system.) There is an article out there which claims that, if you install Java SE 11 and run java -version, it will spit out java version "11.0.7". That will probably satisfy Firebase Tools.
But Oracle's release notes say: 'In Windows and macOS, installing the JDK in previous releases optionally installed a JRE. In JDK 11, this is no longer an option.' No longer an option... as in now you implicitly get JRE 11 with SDK 11? Or as in the SDK and JRE are now fully divorced, and the JRE must be ferreted out of its hiding like a wild beast?
UPDATE 6/5/22: Java's checksums page now says 'JDK', and I guess that is better than 'SDK' because it implies 'Java Development Kit', which this Wikipedia article claims to include both a JRE ('java') and SDK (most of the other files).
To install Java SE:
Go here.
Scroll down to find your product. I chose Java SE 11. (Oracle will probably list later versions as they are made available.)
Choose your operating system. I chose MacOS.
Choose your file set. I chose the DMG installer.
Download your chosen file set.
5. Do whatever is required by your platform to install Java SE using the downloaded file set from #5.
After installing Java SE 11, java -version now says "11.0.14" and Firebase Tools is now satisfied. My best guess is that JRE 11 was implicitly downloaded, and that developers need to start ignoring the main Download page used by everyone else. (Why didn't the main Download page recommend Java 11 from the start?) Hopefully someone will see this question and clarify whether in the future, the 'Java SE' product implicitly includes both the JRE and SDK, and that the numbering system will always encompass both. In other words, hopefully when someone says we need 'Java 11', it means that we need to download SE 11, containing JRE 11 and SDK 11.
This link has a JDK installer that solved my problem today. I needed to close and reopen all my VScode windows to get it to work.
https://www.oracle.com/java/technologies/downloads/
With latest versions this error appears: !! emulators: firebase-tools no longer supports Java version before 11. Please upgrade to Java version 11 or above to continue using the emulators.
You can download Java SE Development Kit 18 from this link. Just choose your operating system, download and install the file. When installation is complete you need to restart you terminal and voila it works now:
firebase emulators:start
But Oracle's release notes say: 'In Windows and macOS, installing the JDK in previous releases optionally installed a JRE. In JDK 11, this is no longer an option.' No longer an option... as in now you implicitly get JRE 11 with SDK 11? Or as in the SDK and JRE are now fully divorced, and the JRE must be ferreted out of its hiding like a wild beast?
With Java 8 and earlier, the end user of a Java application was responsible for providing a Java runtime environment for the application to run on. This is what the JRE was for. The user would have to install this runtime environment on their system in order to run Java applications. This is also why the https://www.java.com/en/download/ page recommends Java 8 (the JRE), which was the last version of Java where an end-user should concern themselves with installing a runtime environment.
Starting from Java 9, it is now the application distrubutor's responsibility to provide a Java runtime that can run the application. So, there are no more JREs.
The application developer should use jlink, which is a tool included in the SDK, to create a 'runtime image' (essentially a bespoke JRE to run a single application), that can be used to run the application, and bundle that runtime image with the application. The jpackage tool can also be used to create application images (including a runtime image), as well as installers.
When the JDK already includes JRE for the execution of code, why do I have to download JRE separately to execute my java code is the doubt that's bothering me
As far as I remember this depends on your OS, browser and JDK version.
Eg. if you're using a 64-bit OS and installed a 64-bit JDK, but are using a 32-bit browser, then you might have to install a 32-bit JRE if you need Java support in the browser.
Otherwise a separate JRE installation should not be required, since the JDK installation also installs the JRE.
JRE: Java Runtime Environment. It is basically the Java Virtual Machine where your Java programs run on.
JDK: It is a group of utilities one needs to develop programs in Java including JRE, and the compilers and tools (like JavaDoc, and Java Debugger) to convert the source code into bytecode.
Refer: http://javarevisited.blogspot.de/2011/12/jre-jvm-jdk-jit-in-java-programming.html
Similar, post is there on below link as well.
What is the difference between JDK and JRE?
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.
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.
I am trying to bundle java as a part of a java product that should be installed silently with a single click and are having some issues:
My installation has the following requirements:
Has no be silent and require no user input or action excpect a doubleclick on the installation file (no configuration and post install steps)
Has to setup java so that JAVA_HOME points to a Java SE installation with a server jvm
Is this at all possible to do this on a win32 system with sun java installers? I know that by default the jre does not contian a server jvm. But even when installing the jdk the public jre which is installed (and mapped to JAVA_HOME) does not contain a server jvm. In sun own README file (Sun README) they suggest copying the files:
jre\bin\server\
On Microsoft Windows platforms, the JDK includes both
the Java HotSpot(TM) Server VM and Java HotSpot Client VM.
However, the Java SE Runtime Environment for Microsoft Windows
platforms includes only the Java HotSpot Client VM. Those wishing
to use the Java HotSpot Server VM with the Java SE Runtime
Environment may copy the JDK's jre\bin\server folder to a
bin\server directory in the Java SE Runtime Environment.
But this solution is difficult to automate gracefully in a silent install. There has to be a better way to do this without repackaging the entire java distrubution. Has anyone encountered the same problem and come up with a more elegant solution?
For the past years, I manage Java like this: I download the installer, install it somewhere, package all files into a ZIP and then use that ZIP file to deploy Java anywhere. The installer will leave a lot of stuff in the registry and %WinDir%, etc. which you don't really need. This also allows me to move some files around (like the bin\server\jvm.dll or security related settings).
That way, I can even embed Java inside the application directory, independent of any already installed version of Java.
Just set JAVA_HOME in a small batch script before starting your application and you're good. You can use %~dp0 to make it completely position independent (%~dp0 expands to the path leading to the batch file).
Make your own installer.
I use inno setup compiler, works well for my purpose.
If you need the registry entries, you can export them, include them in the installer, include the files, and a little change here and there and you're done. Silent installer that configures things to the exact specifications you need.
It comes with an easy to use script wizard.
I mention a specific one because it's free. Ultimately, making your own installer is the solutions.