Issues with new java update - java

More issues with java. I just updated to the newest version of the java jdk and now none of my code is working. Eclipse is saying the type string does not exist, it is not finding the Scanner type in java.util, and I have no idea what happened. I don't know if java majorly changed or what. (Note the version I updated to was java 8 update 92)

In Eclipse, go to:
Window -> Preferences -> Java (open sub-menu) -> Installed JREs.
Then remove the old entries.
Press Add -> Standard VM, and specify the new jdk folder you've downloaded.
Its default location is in C:/Program Files/Java.

Related

GlassFish requires Java SE version 6. Your JDK is version 0 (Mac)

I'm doing a project in IntelliJ with GlassFish and it throws this error:
GlassFish requires Java SE version 6. Your JDK is version 0.
I ran the glassfish4/bin/asadmin start-domain command in a terminal but still get the same error.
I do have Java SE installed, SDK version 8u152 (I checked on Java Panel). Also, I don't know why it searches for jdk 9.
For me java home was good, the only issue was that the version was not matching up.
Open “glassfish -> config -> asenv.conf”.
Add the line AS_JAVA=PATH_TO_YOUR_JDK_DIRECTORY
The only stuff needs to be kept in mind is AS_JAVA=PATH_TO_YOUR_JDK_DIRECTORY should exactly match with the jdk version you mentioned in your intellij.
Now ->
C:\Program Files\Java\jdk1.8.0_40 is mentioned in intellij... file-> SDK's
set AS_JAVA=C:\Program Files\Java\jdk1.8.0_40 is mentioned in glassfish -> config -> asenv.conf
Which me, open asenv.conf in PATH_TO_YOUR_GLASSFISH/glassfish/config folder, go to end of lines and add set AS_JAVA=/PATH_TO_YOUR_JAVA/Java/JavaVirtualMachines/jdk-YOUR-VERSION.jdk
I tried all these approaches and none worked for me.
All answers talk about going to folder PATH_TO_YOUR_GLASSFISH/glassfish/config and then editing asenv.conf.
Editing that file didn't have have any effect.
I did go to that folder but ended up editing asenv.bat.
I literally added this to the end: set AS_JAVA=../../../../Program Files/Java/jdk1.8.0_261
The generic instruction would be: set AS_JAVA=PATH_TO_YOUR_JDK
Note: the asenv.conf file has quotes around values, asenv.bat does not.
I finally tracked the answer down from this question:
How do I specify the JDK for a GlassFish domain?
Go to folder '..\GlassFish-4.1.2\glassfish4\glassfish\config'.
Open in Notepad: asenv.bat
Add in end row:
set AS_JAVA=....\Java\jdk1.8.0_291
In my case, the issue was completely unrelated to IntelliJ setup and JAVA_HOME was pointing to correct path (version 1.8).
Despite that, runtime of java version 9 was actually used, so I uninstalled JRE 9.
Left JDK9, since removing the runtime was enough as a quick fix.

Java + Eclipse: The method computeIfAbsent(String, (<no type> k) -> {}) is undefined for the type

I am using Eclipse (Mars.1 Release (4.5.1)) and encountering the following error: The method putIfAbsent(String, new PriorityQueue<>()) is undefined for the type
Map<String,PriorityQueue<String>>. Everything seems done correctly but still getting the error. What could I be missing?
Map<String, PriorityQueue<String>> targets = new HashMap<>();
...
for(String[] ticket: tickets) {
targets.putIfAbsent(ticket[0], new PriorityQueue<>());
}
EDIT
Did the following, yet still getting the error
EDIT 2
Added Java 8 SE, yet still getting the error.
EDIT 3
There's no method Map#putIfAbsent(K key, V value) in Java 7, but there's in Java 8. See:
Map (Java Platform SE 7)
Map (Java Platform SE 8)
In your specific case, make sure the project properties under Eclipse (described below) are set to Java 8. You can edit them by doing: Right click on project > Properties:
Project properties > Java Build Path
Project properties > Java Comiler
Here's a possible solution:
If your Java Build Path is targeted to Java 7, follow the below steps to change it:
Select JRE System Library
Click button Edit... located on the right side
Use one of the following options
Global: Workspace default JRE. Make sure it is set to Java 8
Local: Alternate JRE. Choose Java 8.
After setting this, you can continue to check the Java Complier.
Now, you should run your project without problem.
Do I have to do this to each project individually or does it apply to all projects?
You don't have to do this for each project. You can have a set-up for all projects of this workspace.
To setup Java Runtime Environments for all the projects, you can check which JREs are installed and change the default one.
Go to Eclipse > Preferences...
Search JRE
Check the installed JREs
If your recently installed JREs aren't appeared, then add them manually one by one using button Add.... Or add them automatically using the button Search....
Select the default JRE that you want
As the screenshot shown: By default, the checked JRE is added to the build path of newly created Java projects. Now it should be OK for all the projects.
To edit the JRE for a specific project, you can. Here're the steps to do it:
Select the target project, right click > Properties
Select Java Build Path
Edit JRE System Library
Choose your preferred JRE version from
Execution Environment
Alternate JRE
Workspace default JRE
Although you have set the compiler settings for Java 8, your project still references the Java 7 System Library in its Build Path (according to the las screen shot in the question, Edit 3). You need to select that system library (JavaSE-1.7) and use the Edit... button to change it to JavaSE-1.8) - the one you added in your "Edit 2" update.
In case you're wondering, the difference is between how the compiler produces .class files for your code (the Compiler Compliance setting) versus the version of the Java standard libraries that are used to compile against (The JRE System Library). The two things are separate but usually configured to match each other.
It is supported only in Java 8.
Make sure the following are checked:
go to your environment variable (start -> type environment variable in search box)
make sure your java_home has your bin for jdk 1.8.x version and it is included in your path. (reference you can also look here: Environment variables for java installation)
After the environment variable is set restart your eclipse. Undefined should go away.

JRE version is 1.6.0; version 1.7.0 or later is needed to run Google Plugin for Eclipse

I have 3 versions of Java installed on my system: 6, 7, and 8... I am required to have JRE6 available for a product my company develops, so I cannot get rid of it... But despite copying my Eclipse install to a new folder for another project I need to work on and removing JRE6 from this version alltogether, I still cannot get it to work.
How can I get the google plugin for Eclipse to work in my scenario?
If you have created a shortcut to start eclipse, you can add a parameter to tell it to use the jre of your choice like this -
C:\eclipse\eclipse.exe -vm "C:\Programs\jdk\jdk1.7.0_55\bin\javaw.exe"
I have used "javaw" executable from a jdk installation, but you may point to the same executable within a JRE installation as well.
This will resolve the error.
Keep in mind that there is a separation between the JVM that Eclipse itself is running in and the various JREs that you can configure in Eclipse to run your programs/applications. You need to specify to Eclipse what JVM you want it to run under, using eclipse.ini.
That's separate from the Installed JREs configuration you show in your screen shot above.
Add Java 7.0 to Eclipse if you haven't: Window -> Preferences -> Java -> Installed JREs.
Next add Java 7.0 library to your project: Right click on project -> Properties -> Java Build Path -> Libraries tab -> Remove JRE 1.6 and add New Library (JRE System Library, 1.7.0).
Last set Java 7.0 compliance level: Right click on project -> Preferences -> Java Compiler -> Compiler compliance level: 1.7
Also since you can use different Java to run applications, you also have to change this in the Run configuration which you use to start AppEngine related tasks.

How to use Java 8 docs in Eclipse

I'm having issues seeing API documentation for Java 8 in Eclipse. Here's an example of the problem I'm having
Calendar myCalendar = Calendar.getInstance();
If I mouse over Calendar then I see all the correct documentation, however if I mouse over getInstance() I get a message saying
Note: This element has no attached source and the Javadoc could not be
found in the attached Javadoc.
I have the Javadoc location for rt.jar set to http://docs.oracle.com/javase/8/docs/api/, I've also tried downloading a local copy of the docs and had the same problem. Changing the link to the Java 7 docs fixes the problem I'm having.
Eclipse seems to be using the wrong anchor style (not sure how else to word it) when looking for methods. When it looks for the getInstance() method, it checks http://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html#getInstance(), but it should be checking
Calendar.html#getInstance--
All brackets and commas seem to have been replaced by hyphens in the Java 8 doc links. I experienced this problem with Eclipse 4.3 (Kepler), 4.3 with the patches for Java 8, and now with 4.4 (Luna)
Is there a way to update Eclipse so that it properly displays the docs in the mouse over tooltips?
Setting the installed JRE to JDK 8 fixes your problem.
This can be done by going to
Window -> Preferences -> Java -> Installed JRE -> Edit -> Directory and selecting the JDK 8 installation folder
Step 1: Windows -> Preference -> Java -> Installed JRE -> Edit -> Directory (Specify the JDK directory (and not JRE))
Step 2: Click "Restore Defaults"
Step 3: Click OK
This worked for me in Ubuntu 14.10, Eclipse Kepler using openjdk-8
Window > Preferences > Java > Installed JREs > Click on your java-8-openjdk > Edit
For /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar:
set Source attachment to:
/usr/lib/jvm/java-8-openjdk-amd64/src.zip
set Javadoc location to:
file:/usr/share/doc/openjdk-8-doc/api/
NOTE: If you don't already have the openjdk-8 java doc, install:
sudo apt-get install openjdk-8-doc
and for the source:
sudo apt-get install openjdk-8-source
I had the same problem. I did set the installed JRE to be JDK8. Still wasn't working until I clicked "edit" on the jre (under 'Installed JREs') then then clicked "Restore Defaults". Then it started working... Looking at each jar in that list I see it sets "Source attachement" and not "Javadoc location". Seems to work.

Java 7 - Mac + Eclipse

I've got an eclipse java project I need to open and run, it was built in Java 7, the default on my mac is appearing as java 6. When I right click the project > build path > try to change the java version .. it says Java 7 (unbound).
I've got java 7 update 51 installed on the mac.
I've tried installing java 7, but eclipse isn't recognising it.
Does anyone know of a solution?
Click that "Installed JREs" button and all will become clear.
Assuming that you have successfully installed an Oracle JDK 7 for Mac, you should be able to configure Eclipse to use that JRE. Here is my setup (using JDK 7u51):
Eclipse does not automatically find all Java instances, but has a list of known JREs.
To add your newly installed JRE, open Preferences, select the Java/Installed JREs page, and try search to find your new engine. If search does not yield results, select the Add... button, on the first page, select Standard VM, and then add '/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home' as the Java home (or something similar).

Categories