Eclipse 2022-06 (4.24.0) does not recognise Java 17 - eclipse

I want to move to Java-17, from Java-11.
Updated Eclipse to 2022-06 (4.24.0).
Eclipse clearly says that Java-17 is the selected JRE.
Entered an example with Text Blocks to test Java-17 features.
Eclipse says: "The Java feature 'Text Blocks' is only available with source level 15 and above"
Eclipse advises:
Set project compiler compliance settings to 15
Set project JRE build path entry to 'JavaSE-15'
In Windows/Settings everything shows v17.
In desperation I removed all other Java version from my Windows machine. Didn't help.
In the terminal window of Eclipse I CAN compile and run the TextBlock example, so JRE-17 is correct. It is that Eclipse seem to be unable to handle JRE-17.
Any suggestions?
Thanks in advance!

The message is referring to the project's own Properties dialog's Compiler Compliance page. Projects can, and often do, override the workspace's settings so that they're retained in source control.

Related

Setting Eclipse STS to use Java 8 to compile java code of my project

I'm very surprised how hard is it to operate Eclipse - almost everything I try to do ends with SE question.
I have a new project which consists of about two files and some external libraries. This project can by compiled manually by a command line script:
rem List all java files in jar/ directory to text file
dir /s /B jar\*.java > sources.txt
rem make javac compile those files and put the .class files in bin directory
javac -cp %PZCLASSPATH% -d bin #sources.txt
I use java 8 JDK for compiling the project. I am not even dreaming of Eclipse ever building the same way (or building properly at all), but at least I'd like to make it use Java 8 for code validation, as to avoid errors for code incompatible with old java versions:
I looked into project properties and tried to find something to set-up:
As you can see, Java 8 is kinda missing in that menu. In NetBeans, I remember just changing the JDK to desired version. Probably better approach than hardcoded menu.
Also the menu doesn't even seem to have much effect, as I see The import java.util.Arrays cannot be resolved error for import java.util.Arrays; command:
So it's not using even the Java 7 now. Note that other projects work fine in the IDE, but this one has been handcrafted so is problematic.
Is there another way of configuring it?
First thing you need to do is make sure that your workspace has access to a Java 8 JRE.
Go to "window >> Preferences". Then type "JRE" in the searchbox. Select "Installed JREs". If no Java 8 is there. Add one.
Now that Eclipse has a JRE available you can start using it in your projects. You can either set the Java 8 as the 'default JRE' by clicking checkbox in front of it in the same "Installed JREs" prefs dialog, or select it for a specific project (this is really the best as making it the default doesn't guarantee a project will use it, since its only a 'default' used unless a project sets it specifically).
Right click the Project and go to "Properties >> Java Buildpath".
Check the "Libraries" tab shows a "JRE System Library" for Java 8. If it shows a wrong JRE, remove it and add a new one, make sure to select one with the right "Execution Environment" you want to use:
Normally this should be enough. The compiler target / source levels generally automatically follow the JRE version. Though... it is actually possible to override that. This is because JDK 8 is backwards compatible and capable of compiling and running to Java 7, 6 etc. So the compiler source and target levels are independently configurable.
So... its best to check them and make sure you didn't override the compiler settings by accident. You already have screenshot for that setting so I assume you know where to find it (Project >> Properties >> Java >> Compiler). However, unlike shown in your screenshot, I suggest that you don't set it specifically, but rather select the option to make it follow the selected JRE:
Final Note: Manually configuring this is indeed a bit painful. People usually don't do that however. If you use maven, for example, then assuming your pom file specifies all the details of how to compile your code and what JRE it requires, then a tool like M2E will configure Eclipse for you, and all that is left for you to do is the first step from my instructions, to ensure that the needed JRE is available to use. M2E will handle all the other steps automatically).

Eclipse workspace projects suddenly have bad build path

I generated several Java projects last spring. Today I opened Eclipse back up and selected the workspace I used in the spring but now all the projects have a red X on them. They all list the same problem:
**The project was not built since its build path is incomplete. Cannot find the class file for java.lang.Object. Fix the build path then try building this project.**
The build path looks ok (I think). I tried to create a new project as an experiment to see it there are differences. The new project dialog box has **Use default JRE (Currently jre7)** checked and a warning at the bottom:
**The current workspace uses a 1.4 JRE with compiler compliance level 1.7. This is not recommendes and either the JRE or the compiler level should be changed.**
Not sure what changed since last spring but something obviously has. I don't really understand what it is trying to tell me. ?Anybody have any ideas I would greatly appreciate it. Thanks.
Update: I created a new project and compared its buildpath to one of the projects from last spring. In the new project, it has: **JRE System Library [JRE7]**
In the old project that now has the problem I see: **JRE System Library [JAVASE-1.7](unbound)**.
Somehow I think the "unbound" means something bad. Still do not understand how it was ok last spring and now suddenly it isn't.
The "unbound" means that there is no JRE at the path specified in the classpath. My guess is that, since last spring, modifications were made to your java installation(s).
To bind your project back on a JRE, click on your "unbound" JRE and click on the "Edit..." button. In the Edit Library window, select a working JRE (JRE 7 would probably be a good choice in your case), then click on Finish. The "Unbound" message should disappear and your classpath should be okay afterwards.

Unbound classpath container: 'JRE System Library [OSGi/Minimum-1.2]' in Eclipse Juno

For my class I imported code from an online source given to us by the professor and tried to run it in Eclipse Juno (i'm not sure if it makes a difference what version) And I got the error message "Unbound classpath container: 'JRE System Library [OSGi/Minimum-1.2]' in project 'cs112'" I researched several answers to this problem and tried multiple solutions including building a path and adding a library, which i named JRE, and setting the correct execution environment! What could I possibly be doing wrong? Please help!!
In the Preferences (Menu Window, Preferences), find "Java", "Installed JREs".
You should have at least one JRE, better a JDK available.
Then, in the same section, there's a sub-section "Execution Environments".
The project you're trying to use asks for "OSGi/Minimum-1.2". The "Execution Environments" preference section allows you to view and adjust how the available JREs are mapped to requested execution environments. If none of your JREs are listed as compatible with the requested environment, you may have to
Install a new JRE or JDK, for example a recent Java 1.7
and, this is important, tell Eclipse about that new JRE by adding it to the "Installed JREs". Select "Add" -> "Standard VM" -> Point to "jdk1.7.xxx".

Mysterious Eclipse javadoc problem

I had a problem with finding Java docs in Eclipse. I seem to have fixed the problem, but I'm posting this for two reasons: I would like to know why I had the problem in the first place and perhaps my method of fixing it might be useful to someone else having a similar problem.
I created a simple Java project in Eclipse (Helios on Windows 7) and selected the JavaSE-1.6 JRE. Then I created a source file and imported java.util.GregorianCalendar. When I hovered over GregorianCalendar, I was getting the message:
This element has no attached source and the Javadoc could not be found in the attached Javadoc
None of the methods of GregorianCalendar seemed to have any Javadoc, either. Other standard Java classes (even others in java.util, like ArrayList) didn't have this problem; only GregorianCalendar. Everything seemed set up properly in the project settings. The Javadoc location set in the Java Build Path was http://java.sun.com/javase/6/docs/api/.
I managed to restore correct behavior by temporarily switching to JavaSE-1.7 and then back. Evidently something got reset and all is well. While I'm happy that things are now working, I don't like being clueless as to how they got messed up in the first place.
Can anyone provide any insights into this?
I think general support relies on the presence of a src.zip in your JDK directory, which is detected when you autosearch a directory for Java installations. It could be missing. Not sure if online Javadocs are used.
I'm using Eclipse Juno on a Windows 7 64-bit (with a 32-bit JDK) but i think it will also apply to your Eclipse version:
Download JDK docs zip file to your Desktop folder;
Right-click on the file, choose Properties and unblock it;
Move the file to a location of your choice. I normally move it to the JDK folder;
Open Eclipse and go to Window->Preferences->Java->Installed JREs;
Select your JDK installation and press Edit;
Select the rt.jar file and click "Javadoc Location..." button;
Select the "Javadoc in archive" radio button;
Set the archive path by browsing to the JDK docs zip file;
Set the "Path within archive" to "docs/api" (without the quotes).
Enjoy! ;)

Eclipse on Mac, getting "Specified VM install not found" error when trying to build

When I try and do an Ant build on my mac (Snow Leopard, Eclipse 3.6 - Helios) I get an error dialog that says
"Problem Occured"
'Launching projectName build.xml' has encountered
a problem. Specified VM install not
found: type Standard VM, name jdk1.5.0_14
I can't even find any preferences setting in Eclipse that specifies for it to use jdk1.5.0_14.
When I went into my preferences and went to the Java section and looked at the Installed JREs, the only one I have specified is 1.6.0. Where is it getting the setting to try and use 1.5? (Or am I barking up the wrong tree?)
Your ant project launcher refers for some reason to a Java 5 environment.
Select "Run as -> Configurations" and locate the ant build. Then indicate you want this configuration to run with a Java 6 JVM.
Delete the
".metadata.plugins\org.eclipse.debug.core.launches\ build.xml.launch" file and problem is solved".
This is just an update of the previously posted solution for later versions of Eclipse, like STS.
If your Ant View is open, R-click on the root (otherwise Run -> External Tools -> External Tools Configuraitons)
Run as -> External Tools Configurations ...
Your Ant launch should be selected in the External Tools launchers, if not selected manually
Go to the JRE tab
Select Run in the same JRE as the workspace - you can also select a different JRE using the buttons on the right.
Re-run your ant task(s) - this time you will not get the error message.
There was a whole bunch of stuff I had wrong that I changed to fix this, but I believe the crucial piece was an %ATG_HOME%/home/localconfig/dasENV.sh file had an ATGJRE a path that was incorrect.
I kept getting "Specified VM install not found: type MacOS X VM, name Java SE 6...".
And i did this accidentally and it worked: Properties-Java Compiler-Installed JREs-Search Button.
It did some soul searching,created yet another JRE entry and it all worked!
Right click on the project and choose properties.
Go to Java Compiler and make sure Compiler compliance level is set to 1.6 rather than 1.5.
I think that should do the trick.