I am using spring tool suite IDE. I have imported one spring project. After running the project I get error as Fatal error compiling: tools.jar not found: C:\Program Files\Java\jre8\..\lib\tools.jar. I tried to use JDK's path in the preferences option. But then it shows another error as diamond operator is not supported in source 1.5. I am using JDK 8 and STS 3.6.3. Can anyone help me solving this error?
I get error as Fatal error compiling: tools.jar not found: C:\Program Files\Java\jre8..\lib\tools.jar.
Trying to use a JDK instead of JRE as you did is the right course of action for this error.
But then it shows another error as diamond operator is not supported in source 1.5.
It is possible to use Java 8 as a runtime yet compile using Java 5 as source and/or target level. This is really independent of the chosen runtime.
Check that you select at least Java 7 for 'source' and 'target' level if you want to use the '<>' operator in your code. This setting can be found by right clicking on your project and going to 'Properties >> Java Compiler'.
You can change these settings right there... but... depending on your project's setup this may not be the best idea. For example if your project is a maven project then you should configure compiler settings via maven compiler's plugin as shown here:
http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html
If you change the settings directly in Eclipse's UI those settings may be lost as soon as maven updates your project.
For that project, RightClick -> Properties -> Project Facets -> Change the java version to Java 1.7.
The diamond operator (empty "<>") was introduced in 1.7.
Check the Java version in the launch configuration wizard. Right-click on the project Run As -> Run Configurations... then select your project's launch config in the explorer on the left and check the contents of JRE tab on the right.
Also go to Preferences -> Java -> Compiler, ensure that Compiler Compliance Level is at to 1.7 at least.
Related
Have a java project with couple of main java classes in it. On server this program has to run using java 1.5 version.
Trying to setup the same in eclipse.
Project properties/Java compiler ---- set to 1.5
Project properties/Java build path ---- Added JRE library ---> J2SE-1.5
But, when running one of the main class in the project in eclipse getting error as
SEVERE: Java Runtime Environment (JRE) version 1.6 is not supported by this driver
what else do I need to do in eclipse to run the program using java 1.5??
Go to Window -> Preferences -> Java -> Compiler and choose the default compliance level as 1.5
In Project properties/Java compiler make sure that 'Enable project specific settings' is checked.
Also, I would double check the build path for duplicate JRE libraries
IntelliJ is showing me this error
I just built my new computer and none of my java stuff is working... My regular Intellij was working when I first tried it, but my android studio would't install because it couldn't find the path to the jdk. Here is the question that I asked about that. Since that wasn't working, I had to reinstall java multiple times, and now my IntelliJ isn't working. Here is a picture of the error (I am getting an error that is telling me the for-each loops aren't supported at this language level).
I have tried to install the JDK on my D: drive and that didn't work. I am currently trying to use java 1.8u71 (have tried u65 and 1.7u47) except none of those have worked.
IntelliJ is showing me this error
Matching the SDK/JDK with Project language level
To activate Java language features in the editor, you need to change your module's Project Structure or Module Settings to ensure your Project SDK matches the Project language level.
Project SDK (JDK) Java 1.5 matches project language level 5 ...
Java 1.6 matches language level 6 ...
Java 1.7 matches language level 7, and so on.
Example
Depending on your IntelliJ version, hit F4 or Ctrl + Alt + Shift - S on your module in the Project pane, or hit Ctrl + Shift - A and type either "Project Structure" or "Module Settings" to open the Project Structure dialog.
Under Project Settings section, click on the first item in the list, Project.
In the screenshot below, the Project SDK 1.8 (java version '1.8.0_72') matches the selected language level SDK Default (8 - Lambdas, type annotations etc.) because Java 1.8 matches SDK level 8. This activates the Java 8 language features for use in the editor.
If you don't have the JDK set up under Project SDK that is a different problem. Solve that one first by clicking New and adding a JDK.
When I had multiple independent modules in the project, I had to do below setting in addition to #activedecay's answer:
Under Project Settings, click on Modules. Select specific module. Select appropriate Language Level.
I had this same problem and none of the solutions I have found worked.
I was using Maven projects and so decided to try running a maven install. It too said:
[ERROR] thefile.java:[24,77] diamond operator is not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable diamond operator)
[ERROR] theFile.java:[91,62] lambda expressions are not supported in -source 1.5
[ERROR] (use -source 8 or higher to enable lambda expressions)
So I added the properties to the Maven build pom.xml file:
<properties>
<spring.version>4.1.6.RELEASE</spring.version>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
And refreshed the Maven project in IntelliJ. It worked!
I also had the same problem.
While I was accessing a static method of an interface through the name of the interface, I got the error saying
static interface method invocations are not supported at this language level 5
As this is Java 1.8, I have checked some things:
I am using Intellij. So by doing CTRL+ALT+SHIFT+S Project Structure dialog box opens, go to
Project -> Project language level
set this to SDK default (8-Lambdas,type annotations etc).
In Project structure open
Modules -> Sources -> Language level
set this to Project default (8-Lambdas,type annotations etc).
Apply-> OK.
Then the error will go away.
Let me tell the solution in one image.
File -> Project Structure -> Modules -> Properties tab -> Source Compatibility (Java 8)
Another issue I had that caused this error in a Gradle project was the sourceCompatibility setting in the build.gradle file. This must also match the value you are expecting to need. The default value that I have seen IntelliJ use when creating a new Gradle project is 1.5. If you are using lambdas, for instance, this will cause the build to fail.
While trying to do a maven compile goal on a jar project in eclipse it failed stating that there was no java compiler found. It showed that it was using the path to jre1.8.0_45. My configured java build path in eclipse is using jdk1.7.0_80 and is configured for the correct corresponding environment.
I tried to rename the jre directory while eclipse was open but it showed that something had a lock on it, and sure enough it was eclipse that was launching with jre1.8. If I renamed the jre1.8 directory while eclipse was closed, then it would not launch again complaining that it cant find the java directory.
I guess what I'm getting at here is, is this a bug with Mars? Or am I missing something because everything in Eclipse is pointed to 1.7.
Thanks,
Nate
You should point Eclipse to JDK installation.
Window -> Preferences -> Java\Installed JREs
click Add -> Select Standard VM, Next ->
and then in text box "JRE home" you should put path to JDK home,
it's quite misleading..
BTW you should specify java version in maven-compiler-plugin. M2E plugin will then recognize this settings and configure compiler appropriatelly
http://www.gamefromscratch.com/post/2011/11/15/Telling-Eclipse-to-use-the-JDK-instead-of-JRE.aspx
It's the launch configuration of any m2e build that should point to a full JDK, cf. http://help.eclipse.org/mars/topic/org.eclipse.jdt.doc.user/tasks/task-choose_config_jre.htm?cp=1_3_5_2 (except you will be using a Maven Build configuration, rather than a Java Application).
For most other situations using a JRE should be perfectly fine.
I am getting this error while trying to compile some simple source code in idea ide.
java: diamond operator is not supported in -source 1.6 (use -source 7 or higher to enable diamond operator)
jdk is 1.7.40 from oracle
but where is this place to add this "-source 7" option?
i tried adding in ide settings but that had no effect.
You need to set the project language level (default for all modules) and the module(s) language level
Make sure that, in the Project Structure page, you have set your project language level to 7.0.
After you select this, you will have to reopen your project, but then your diamond operators should compile.
Check Project Structure tab in IDEA, find the followng navigational path
Project Structure -> Project -> Project SDK
Follow these steps.
Right Click on the project------>> go to Open module Settings--->
In that opening window click the Project in project settings---->
and set project SDK
Under File -> Project Structure -> SDKs i have 1.7 jdk but i still get this error:
added.java: try-with-resources is not supported in -source 1.6
(use -source 7 or higher to enable try-with-resources)
I have restarted IDE but to no avail
Newer JVMs allow you to compile your code using compiler versions of lower JVM versions. For example, JDK 1.7 will allow you to compile your code using the 1.5 compiler.
See the "Cross compilation section" here http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html
What you need to do in Intellij, is to go to File -> Project Structure -> Project and select the "Project SDK" as 1.7 and the "Project Language Level" as 7.0
Had to click on the 'error bulb' icon (or Alt+Enter) and select option to enable load multi-catch, try with resources, diamond ... and then reload and restart IDE.
IntelliJ IDEA allows to set the language level on a project basis as well as on on module basis. If you have set the language level to Java 7 or higher on the project level, and are still getting this error message, right click on the module, select "Open module settings". Make sure the language level for the module is set to "Project default", or if for one reason, you want to set it specifically, it should be at least Java 7.
I had the same problem with IntelliJ 13. You have to set the language level, either for the entire project or individual modules, on the "General Settings for Project" dialog. See IntelliJ IDE gives error when using Try-Catch with Resources for the complete answer.
If the above answers didn't help, are you using Groovy? Apparently Groovy doesn't support Java's try-with-resources in the current version.