Why aren't there compatible JREs for JavaSE12+? - java

I am getting an error when trying to run a .java file as a Java Application and I get the following error:
Unbound classpath container: 'JRE System Library [JavaSE-14]' in project <project_name>
I tried to change the execution environment and for JavaSE12 and later versions there are no compatible JREs. (But for JavaSE11 the compatible JRE is java-11-openjdk-amd64)
I do not know what to do because the project I am working on doesn't work with old Java versions. How can I choose an environment for the latest Java versions?
Note: I am using Ubuntu 20.04 if that makes any difference.

tl;dr
I am not a Linux user, so I may not know best. But I suspect the simplest approach to running your .java file is to:
Obtain and install a JDK for Java 15 for Linux
Call java app on the command-line, passing the path to your .java file.
Backwards-compatibility is a priority for the Java team. Most any existing Java app should be able to run with the latest version of Java. There are exceptions, but they are very few.
JRE is passé
The JRE (Java Runtime Environment) was a subset of the JDK (Java Development Kit), omitting some of the programmer tools. The JRE as a separate product seems to be getting phased out.
Oracle and much of the Java community has shifted away from the idea of regular users having Java installed on their personal computers. Instead, apps should be delivered with a JVM specific to their host platform bundled within the app. This bundling of a JVM can be done using newer tools such as jlink and jpackage.
For more info, read:
Java Client Roadmap Update - Oracle (2020-05)
Java is still Free
Obtain a JDK
You said you have a .java file to execute. That file must first be compiled before it can be executed. The more recent versions of the java app can do both steps at the same time, compile & execute.
First download and install a JVM for your host platform.
Java 11 is the current long-term support (LTS) version. Java 15 is the latest release. You may want to read about the six-month release cadence for Java.
You have a bounty of vendor choices providing implementations of Java. Here is a graphic flowchart I made to assist in choosing a vendor.
If the steps shown here are overwhelming, I suggest either:
Using apt-get or similar package installer to obtain a build of OpenJDK for Ubuntu. I am not a Linux-user, so I do not know the details.
Head over to AdoptOpenJDK to download an installer for Linux.
Some motivations to consider in selecting a vendor.
Compile & run your app
Once your JDK is installed, on a console (such as Terminal.app in macOS), run something like the following. The java command should both compile and execute your .java file, if that single file makes up your entire app.
java /path/to/some/folder/MyJavaApp.java

Related

How get a Mac JRE (on linux) that is ready for embedding?

For years I have distributed a piece of software that relies on javafx, and the solution has been to include a JRE in the distributed software and run my .jar file with a script that sets JAVA_HOME. It has worked great.
The Mac version has always been a challenge: I have to download the .dmg from java, unpack it, and tweak the script for (historically) a different directory structure (which may be an artifact of the .dmg packaging, I don't know). But it always worked. (I do this on Linux.)
I recently updated the included JRE to the latest version (1.8.0_291) and it no longer works on the Mac, even after I corrected for the new directory structure. Users report that the script errors with:
Error: could not find libjava.dylib
Error: Could not find Java SE Runtime Environment.
...and indeed, there is no libjava.dylib. In the previous Mac JRE version I was using (1.8.0_92) this file was at:
lib/jre/Contents/Home/lib/libjava.dylib
...but it is not present anywhere in the latest. I also note that the latest JRE totals 107 MB, where the older one was 164 MB, so it would appear that there is something I'm not understanding about these more recent JRE downloads. E.g. perhaps the mac version requires an installer to run to be complete?
Where can I download a distributable Mac JRE?
Failing that, what is the proper way to make a contained Mac JRE?
It appears that AdoptOpenJDK is a good general way to go for multi-platform pre-built JREs, but they do not include JavaFX.
I attempted to use OpenJDK in conjunction with libraries from OpenJFX from openjfx.io, and although my application superficially worked, there were very many exceptions implying poor compatibility between the two. (I was unable to match versions precisely for JDK 11. It's possible that the latest version of both (JDK 16) might interoperate better.)
I found the Liberica JDK from BellSoft. Their "Full JRE" includes javafx and is working. I do get one swing-related exception on startup, but it doesn't seem to matter to functionality.
Apparently there is also the Azul platform, but I have not investigated it.

JDK folder not available under program files [duplicate]

To tell the truth, I am quite confused on all these terms (JDK/JRE/Java SDK). I am not sure what each one does.
When I first started doing simple java examples in eclipse, I am pretty sure I only had the JRE, which I believed was the default java installer regular users use to be able to run java programs/applets on their system.
However, now in class we are using Google Appengine, and this requires the JDK which I am guessing is the same as Java SDK. After wasting some time finding out that installing the JDK meant I also had to add java/bin to the environment variables to get javac -version to work in the command prompt I find that only the JDK has javac...
How were my early java programs working without having installed the JDK and therefore not having javac? And really the main question... What is the difference between the JRE and JDK, and when do you use each one?
Thank you :)
JRE = Java Runtime Environment - what you need to run programs/software that require Java or use libraries written in Java. For example, OpenOffice requires the Java Runtime Environment
JDK/Java SDK = Java Development Kit/Java Software Development Kit - what you need to write programs that require Java or use libraries written in Java. For example, if you were to write your own word-processing tool in Java.
java comes with the JRE because it launches the VM (virtual machine). It can take in class files which are files that have been compiled using the JDK.
The JDK comes with javac because that's what you need to compile your .java files into .class files that can then run on the JRE.
Eclipse has its own built-in compiler (called ecj), which is probably the reason you could get away with not having the JDK installed to use it. It does not use javac.
Google App Engine uses the javac that comes with the JDK.
What is the difference between the JRE and JDK and when do you use each one?
JRE: Java Runtime Environment. It is used to run Java programs only. As Chris Jester -Young mentioned, Eclipse had a built in compiler. That's why you just needed JRE ( to run eclipse )
If you ship a Java program, the only thing the client need to have is this runtime environment
JDK: Java Develpment Kit, this also includes a JRE inside, but additionally have other tools for program development such as the java compiler javac among many others.
If you want to create java program you should use this.
There's no way you used the JRE to compile Java programs. javac, the Java compiler, only comes with the JDK.
You may write Java programs with whatever text editor, you don't need anything special to do this.
You need the JRE to run Java programs. The JRE includes the Java Virtual Machine, needed to run already compiled Java programs.
You need the JDK to compile Java programs. So if you are a Java developer, you may want to only install the JDK since it comes with the tools needed to compile, in addition to the Java Virtual Machine.
'Sometimes you can develop with jre'
No. Never.
You develop with the Java Development Kit. You run with the Java Runtime Environment or Engine or whatever it's called.

Can I develop Java programs if I have only JRE installed?

I have JRE 1.7 installed on my system. Due to some admin issues I don't have JDK on my system. is there any way I can develop Java programs with JRE only?
No you can't develop java programs only with JRE
You will need JDK for compiling your programs.JRE provides only runtime environment,but JDK is something you will need to compile your code to make them executable by your JRE.You will need javac for compiling your code which is present in JDK.
However for resolving the issue of admin rights you are having, you can download and install eclipse which has its own built in compiler.
You need some program which compiles your sources, but that doesn't neccessarily have to be the JDK.
For example you can download Eclipse which only requires a JRE, it has it's own compiler (built-in) and you can develop with that. Eclipse does not require any admin priviliges, it's a zip file which you can download and extract.
You need to compile them in order to develop and that is why you need jdk
You can't develop any Java application since you need JDK(Java Development Kit) to compile your code. JRE(Java Runtime Environment) provides run time environment only. You can run your compiled code in JRE.
the answer is somehow "yes,but..."
java source code execution procedure is split into 2 steps :
1)compiling the source code into a byte-code,thus generating the .class file
2)interpreting the VM specific instructions from the .class file into native instructions
.java----javac---->.class----java---->native code
needless to mention that the "javac" , the compiler of the java source code is in not part of the JRE!
so in order to develop java programs without JDK you have to skip the first step and keep using exclusively the "java" tool,thus dealing directly with byte-code !
in some extent and if you're acquainted with the JVM internals,it's possible to write some lines of byte-code using hex or text editors and then running the .class file;but you will not go further then that specially when it comes to creating complex applications as this require super-human capabilities :that's a highly daunting task .
nevertheless,todays java frameworks almost all use direct byte-code manipulation and tools like the asm framework or javassit
javassist does not require the JDK and you can generate a class from scratch and then compile/run it
java -classpath .:javassist-x.x.jar test "some arguments"
(no need to compile classes)
but again,that is only for restricted use and in order to develop java applications you have to use some JDK...
finally,you have to strive to acquire full control upon what is running in you machine;recent frameworks are resource-greedy and needs a huge amount of resources(disk space,memory...) and many tools and framworks require full control,i mean administrator right : for instance i remember that once a time borland delphi refused to start and i had to give it full access rights to start...
I request you to resolve admin rights. Else I have two options for you.
1) You cannot do anything without Java Development Kit.
2)You can install a IDE to code Java which makes your work in the current situation simpler. Use Eclipse or NetBeans. I would recommend Eclipse to you anyway. You can download eclipse from this link https://www.eclipse.org/downloads/
Try downloading JDK from this http://www.oracle.com/technetwork/java/javase/overview/index-jsp-138218.html.
Hope this helps you.
JDK is needed to compile your java file into class file. And JRE will execute the generated class file and provides the output.
If you have admin problems in your m/c then you can install the JDK in some other m/c and take the class files into your system and execute them.
Eclipse includes its own compiler and doesn't depend on the JDK compiler. But indeed, the JRE is just the runtime environment and doesn't include the compiler or other development tools.
Do you need this to do you job or not? If it's your job, you should have access or they should install it. If you don't have access because it's not your job, I suggest installing the JDK at home (or on a laptop you can take with you)
Due to some admin issues I don't have JDK on my system.
Install it in your home directory or another directory you can write to. Your admins can't prevent you from installing the JDK if you have enough disk space.
JRE is not just sufficient, without compiling the code for that you need Jdk which have compiler to compile the code.

Java Browser Plugin Or Manually installing Java

Here is my question i installed Java Plugin for Chrome it does mean i have installed java in my machine...And after installing this plugin can i run below command
java -jar myfile.jar
through a batch file or i have to install java in my machine and setup class-path then it should work?
If i will install Java browser plugin it automatically installed java in my machine and setup path as well.
Its hard for me t understand the situation how it works. Can anyone help me on this?
The JRE is the Java Runtime Environment, i.e. the software you need to interpret and execute Java class files. The Java browser plugin is the bridge between the JRE and the browser, used to run Java classes of applets embedded in HTML.
You can check the Java plugin of Chrome browser in this link.
The plugin is bundled with the JRE, and runs inside a browser, allowing Java code to run inside the browser process on the client. The main entry point class must be written as an Applet when the plugin is used, but all the Java code it calls can be just regular Java.
There are limitations when running Java code with the Java plugin for security reasons. All code shall run within sandbox with limited access to the file system and such.
Also as the plugin check for installed JRE version at your machine, that means you do have JRE.
You can install as many JDKs as you like. Just put them in different folders.
The one you refer to on the path is your choice - but presumably you'd choose the one that you want to use whenever you type "java ...." commands at the command line. In the absence of any other factors you should probably set this to be your most recent JDK version.
Note that your IDE may support multiple JDKs, for example Eclipse has "Preferences / Java / Installed JREs" where you can set up multiple JDKs/JREs for use with Eclipse
Please first check your machine contains java (jdk or jre)
java -version -- if you get a valid output then you have java in your machine.
in order to run java -jar myfile.jar , you should install java (jre or jdk) in your machine and class path set to the relevant location. To run this you should install jdk or jre in your machine. Most program only need the JRE (Java Runtime Environment) but some programs need the Compiler at runtime in which case you need the JDK.
Please refer this link to find out How to set class path .
Then you will be able to run your command.

Selecting the correct Java, JRE and JDK versions when building an executable JAR for distribution?

I am putting together my first Java package for distribution to users, and am running into some difficulties. I have jar packages that I've built that users can't run; the error messages vary, but are all "version" something or another. I suspect I'm selecting the wrong build paths, and I'm not quite sure where to start troubleshooting because I don't clearly understand the differences between the Java executable (javaw.exe), the JDK and the JRE; I have some questions that I'd like answered which will help in that understanding. I'm used to the way that C# executables compile in VS; wrapping my head around how executable jar files come together is still a little mysterious to me.
Although I've done a few google searches, most of what I'm finding is how to build a jar file, but not how to manipulate/use/select the Java, JRE and JDK versions appropriately to ensure compatibility. I do understand that the JRE includes the virtual machine that allows Java bytecode to run anywhere, and that the JDK includes development tools...but as to figuring out which version I AM running, vs which version is used when building jar files and which version SHOULD be used...I am completely lost.
I'm using Eclipse Indigo under 64-bit Win7. My build path includes the following:
JRE System Library: C:\Program Files\java\jre7\*
External paths: C:\<MyDocuments>\java\lib\commons-io-2.4*
I also have, installed on my machine, the following paths which are NOT included in the build:
C:\Program Files (x86)\java\jre7\
C:\Program Files (x86)\java\jre1.5.0_22\
C:\Program Files (x86)\java\jdk1.7.0_21\
The users that will be running this executable file are only supported (by corporate IT) up to JRE5. I suspect that my building this pointing it jre7 is one of the things that's messing with me.
My first stupid question is whether there's a difference between "Java" and the "JRE" when it comes to version numbers. For instance, when I read about JavaSE7 or JavaEE7, are they talking about the JRE version for the standard or enterprise editions? Are the development kits and runtime environments just components to JavaSE/EE? Or are they separate and distinct products?
Then, my understanding is that I should build this jar using the lowest-common-denominator JRE expected from my users. In this particular case, because the corporate standard is JRE5, I should build this pointing to JRE5 instead of JRE7. Is that a correct assumption?
Does it matter if I build using the 64bit or 32bit version? Some older machines may still be 32bit running JRE5, so I need to make sure I'm backwards compatible.
The Program Files (x86) naming conventions confuse me. JRE7 installed as \jre7. However, JRE5 installed as \jre1.5.0_22, and I also have jdk1.7.0_21, which, based on the JRE name, I assume to be the Java7 Development Kit. Do I need to install the Java5 Development Kit to properly build this program? And am I properly interpreting the versions from the filenames? that 1.5 represents Java5 and 1.7 represents Java7?
Then, my last question I know there's an Eclipse option to copy the external libraries to the project. I assume that if I do this, this will be included with the jar so the users do NOT need to have the Apache Commons jars on their local machines in order for this to run properly. Does the manifest include any confirmations that these files were included? I've been unable to find any references...so I'm trying to verify if I'm even pulling the Commons libraries over and where to look to get that confirmation.
This is just speculation, but I think you may have to re-write the program with the java5 jdk, because some of the APIs/libraries used in java7's jdk may not be recognized by the java5 jre. (Just like it wouldn't be possible to play PS4 games on a PS2... without any serious modding)
If you write the program in Eclipse, you can just select what library you want to use as you create the Java project. At the "Create a Java Project" screen, you can select the "Use an execution environment JRE:" or "Use a project specific JRE" or "Use default JRE" option. (I have jdk6 and jdk7 installed on my computer so I'm able to select those two options; which is why you may have install the jdk5 in order to create a java 5 project.)
You are properly interpreting the filenames. jre1.5.0_22 is java 5 update 22.
There is a way to specify which JRE is used to run the jar file.
cmd prompt >
"C:\Program Files (x86)\java\jre1.5.0_22\bin\javaw.exe" -jar "filepath_filename.jar"
Drop the "w" from the javaw.exe, and you'll be able to see any console and/or stack trace output.

Categories