Java Program Won't Run Due to JRE Version [duplicate] - java

This question already has answers here:
No JREs installed in the work space that are strictly compatible with this environment
(2 answers)
Closed 2 years ago.
I'll premise by saying I am new to Java
I'm trying to run a program in Eclipse. I really haven't done much at all in terms of building the program, I pretty much just added a GUI using JFrame by following a Youtube video.
My problem is that I'm getting this error whenever I try and run the program:
Description Resource Path Location Type
Build path specifies execution environment JavaSE-14. There are no JREs installed in the workspace that are strictly compatible with this environment. Calculator Build path JRE System Library Problem
I'm running SE-15. How should I fix this?

It appears that you installed the latest version, 2020-09, along with Java 15.
It's useful to know that Eclipse can run with a particular version of Java, even while your applications run in Eclipse with a different version of Java.
You have provided Java 15 to run Eclipse with, and that is what Eclipse assumes it will run applications with, by default.
However, at this point in time, the support in Eclipse for features that are new to Java 15 is experimental. There is an additional plugin you can install that will unlock the Java 15 features, although you probably don't need those yet.
Because the Java 15 features are disabled by default, it's using the execution environment of "JavaSE-14", but you don't have a Java distribution that is strictly compatible with that interface.
As a commenter pointed out, this is only a warning, so it's not likely actually causing a problem. You could likely get by ignoring this warning and focusing on the real errors in your application.
However, addressing the warning could be done in two different ways:
Install a distribution of Java 14, add it to the "Installed JREs" list, and edit the "Execution Environment" for Java 14 to refer to the Java 14 installation
Install the plugin that enables Java 15 features (I haven't done this), and ensure that the project uses the "JavaSE-15" execution environment (install the plugin from the "Marketplace Client", entering "Java 15" in the search field)

Related

Ubuntu: Unable to start eclipse

I removed java-11 and installed jdk-1.8. Now when I try to start eclipse then its throwing the following error:
Being a beginner I searched and found some solutions but not worked for me
Ok. I'm going to make some assumptions based on some implications of what you've said here.
I assume that you had Java 11 installed, and you had installed Eclipse, and it was working.
You then, for some reason that I can't understand, decided to uninstall Java 11 and replace it with Java 8.
The error message is because when you had Java 11 installed and you installed Eclipse, Eclipse stored the path to the Java 11 distribution in the "eclipse.ini" file. Now that Java 11 is gone, it cannot start up.
The easiest way to fix this is to reinstall Java 11, and hopefully it will install into the same location as that error message shows it is looking for it.
Now, to address why you might have thought to replace Java 11 with Java 8. I'm guessing you're working on an application that requires Java 8 to compile and run. In this context, it's somewhat understandable that you would have done what you did, but it was the wrong thing to do.
Eclipse can run with one Java version, but build and run applications with a different Java version. In fact, I think it's generally a good idea to run Eclipse with the newest version of Java it can run (generally about a version short of the latest), but build your applications with the version of Java required for those applications.
So, you should have both Java 11 (or newer) AND Java 8 installed. Run Eclipse with Java 11, and build and run your applications with Java 8. In Eclipse, you have to register the Java 8 distribution in "Installed JREs" in Eclipse preferences, and also record that Java distribution in the "JavaSE-1.8" Execution Environment, in the preferences tab right below "Installed JREs". Set your application to require "JavaSE-1.8".

javac: invalid target release: 13

I have been working on some class projects on a work computer with NetBeans 11 and uploading my progress to github. Recently, I came home and pulled my progress down to my laptop which still has netbeans 8. All of a sudden, when I try to run code, I get:
javac: invalid target release: 13
From browsing stackoverflow and other such forums, I gather that 13 refers to the version of the JDK. Apparently, there is some mismatch in my settings (either I am using an old version but NetBeans wants to use something newer, or maybe the other way around).
I went into project > properties > sources and saw a drop down bar titled "Source/Binary Format" with JDK 13 selected. I dropped it down to 9 (a completely random choice) and then tried to run my code again. Voila, it worked.
My questions are simply: What did I just do? Why did it work? Are there any implications for my program to be considered?
If you choose to answer please be aware that I know little about the inner workings of Java, and so a simple explanation is appreciated. I only know how to write the code, not what happens behind the scenes. I'm tempted to blindly plow forward with my coding, but I thought this might be a learning point. Perhaps not.
Basically, your IDE checks your code according to the rules of the language, and those those are different depending on language version because e.g. Java 7 has no lambdas but Java 8 does. Your project was configured to be checked against the rules for Java 13, but the older version of NetBeans wasn't able to do that, so you've asked for it to be checked against the rules for Java 9 instead. This will have no impact on your project unless you want to use features introduced in Java 10 or later.
The other purpose of this drop-down menu is if you want to compile your project so that it can be run using an older version of Java. If you're distributing a piece of software for users who still only have Java 8 installed, then you would want to limit the project to Java 8.

Can't download Java 7 because my computer already has Java 8

I am trying to download Java 7 on my mac. All my professors require java code to be in Java 7. I have the dmg downloaded but when I double click the icon to install I get the error message :
A newer version of Java is already installed.
The only thing I can do is click close and it exits the install. How can I install Java 7 onto my machine?
If you are doing your "development" using an IDE like eclipse, there is a simple solution to your problem: within eclipse, you can change the "compatibility" mode for your projects.
Meaning - even when only Java8 is installed, you can instruct eclipse that your project should be using Java7 only. So when you write source code that uses Java8 features (like lambdas or such things); you will get compiler errors.
The only caveat: you still could be using classes/methods from the Java8 installation that don't exist in Java7.

How to change NetBeans Java Project Runtime?

How can I change the Projects Runtime Platform?
(standard NetBeans [8.1] Java Project [Java Application])
Details:
using Ubuntu with NetBeans 8.1
I have installed JDK 1.6, JDK 1.7 + JDK 1.8
My projects platform is Java 6.
My systems default Java is Java 7.
NetBeans-IDE was started with Java 8.
When I run the project via the IDE (Run project), the Project-Platform is used (which is Java 6).
I cannot change the Runtime Platform!
It's always: Project Platform
I tried to Manage Platforms..., but I still can't change the value of the Runtime Platform-ComboBox.
EDIT:
As I wrote in the comments, I don't want to change the Project-Platform.
The project should be compiled with Java 6 but run with Java 8 (when click on Run project).
What I want is:
Project-Platform = Java 6 (used to compile),
Runtime-Platform = Java 8 (used to run).
How can I change the Projects Runtime Platform?
Unfortunately you can't. As you point out, its value can only be Project Platform. Of course that invites the question "What is the point of even having that Runtime Platform field?".
I suspect that it may have been (unwisely) added to the GUI so that at some time in the future it will be possible to actually select a different JDK to run against. There is an open Bug Report for this: Bug 186747 - Can't Build and Run with Different Java Versions.
It's also worth noting that the Help documentation for the Run screen does not mention that Runtime Platform field. My own view is that the field should be removed until it serves a useful purpose.
What I want is: Project-Platform = Java 6 (used to compile),
Runtime-Platform = Java 8 (used to run).
Unfortunately that can't be done, as shown by the open bug. The best you can do right now is:
Create platforms for JDK 6 and JDK 8 in NetBeans.
Set the Java Platform to JDK 1.6 on the Libraries screen, and set the Source/Binary Format to JDK 6 on the Sources screen, then build to verify that no invalid APIs are being used.
Switch the Java Platform to 1.8 on the Libraries screen to run your 1.6 code under 1.8.
I realize that you don't want to do that, but unfortunately there's no silver bullet in the current release of NetBeans (8.2).
An alternative approach would be to build and run using only JDK 8, but include the Animal Sniffer Maven plugin "for checking projects against the signatures of an API", to verify that your 1.6 code was not using illegal APIs. But of course that's only viable for Maven projects.
Please look at Netbeans Project Setup - Setting the Target JDK in a Project
You just have to change the Runtime Platform at the Libraries option, that's all.
Just went through this pain for Apache NetBeans 14. I was trying to set a remote debug for a Raspberry Pi.
It works only if the jdk match on both the local and remote versions. In my case I set them both to 17.
I would have expected that the default jdk on the local machine should have been able to be changed but I fail to determine how.
I am running Ubuntu on the local machine so maybe the platform cannot be changed (don't know). Moving on.
Changed runtime platform

Why do some Java programs ask for a JDK and some for the JRE? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Java SE 6 vs. JRE 1.6 vs. JDK 1.6 - What do these mean?
I found that sometimes applications ask for java_home to point to a JDK and won't work with a JRE.
Why is that the case? Is it correct?
Short version: some applications use libraries/code that is contained only in the JDK.
Longer version: Usually every Java program should be able to run with just the JRE. And most applications actually work with the JRE.
Now the JDK comes with some additional libraries and tools that you usually only need when developing applications (and not when you simply need to run them).
But occasionally an application decides to use some of the code that gets delivered with the JDK when it runs. It's very rare and is usually not a good idea (unless that application is itself about developing Java applications).
A good example where old versions of Apache Tomcat: it used the Java compiler bundled with the JDK to compile JSP code into bytecode. For this it used tools.jar which is included in the JDK but doesn't get delivered with the JRE.
Newer Tomcats switched to a separate compiler (I think it's based on the Eclipse compiler) for this and no longer require the JDK: they run just fine with just the JRE.
#Rekin mentioned another good example: Maven uses the JDK because it actually compiles Java code.
One application I worked on was using the JDK to compile automatically generated java and load it for user after that (a db-oriented compiler/runner).
#Joachim has a more complete answer.

Categories