I'm using Spring Tool Suite and m2e to convert some of our existing projects to Maven projects. The project in question uses jdk1.6.0_20 which is named [jdk1.6] in Eclipse. When I do Maven -> Update project, though, it replaces that jre with the standard [JavaSE-1.6]. While they seem to point to the same libraries, the change in name causes a bunch of exceptions like:
Access restriction: The type WindowsPopupMenuSeparatorUI is not
accessible due to restriction on required library C:\Program
Files\Java\jdk1.6.0_20\jre\lib\rt.jar
My pom.xml has this:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
Is there any way to get Maven/m2e to use the default workspace JRE instead of replacing it with a specific one in the .classpath?
Go into Configure Build Path on the project and go to the Libraries tab.
Remove the JRE System Library
Click on "Add Library..." and select "Workspace Default JRE"
That will give you the current JRE and not specify a specific JRE
Adding maven-compiler-plugin to your pom forces maven to use given version of Java:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
However if you have both jre and jdk installed on your system (for a particular java version), maven may choose jre and then complain that it needs JDK. This may happen after using Maven > Update Project in Eclipse.
To solve this, in Eclipse, right click on JRE System Library > Properties > Environments and select JavaSE-1.8. If you have more than one compatible JREs in your system then tick the jdk1.8.x > OK > select JavaSE-1.8 (jdk1.8.x) as Execution environment > OK
Now maven should choose Java version 1.8 and Eclipse will tell maven to use jdk1.8 as the default JRE for this java version.
It turns out there doesn't seem to be a way to do this with Maven. Instead I changed the error to a warning in Eclipse settings while I work with the owners of the offending code to fix the problems.
Related
I have an Eclipse Mars 2 Java8, Maven 3.5.4 based workspace.
I build the project files with mvn eclipse:clean eclipse:eclipse, and watch the following maven output:
[INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-**1.7**
The default JRE for the workspace isn't Java 7, it is Java 8, like you can see looking at the following Eclipse config file:
<workspace>\.metadata\.plugins\org.eclipse.core.runtime\.settings\org.eclipse.jdt.launching.prefs.
that contains the following data:
org.eclipse.jdt.launching.PREF_VM_XML=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?>
<vmSettings defaultVM\="57,org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType13,1538040823497*">
<vmType id\="org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType">
<vm id\="1431694854640" name\="jdk1.7.0_40" path\="C\:\\Program Files\\Java\\jdk1.7.0_40"/>
<vm id\="1447417000092" name\="jdk1.6.0_45" path\="C\:\\Program Files\\Java\\jdk1.6.0_45"/>
<vm id\="1538040823497" name\="jdk1.8.0_65" path\="C\:\\Program Files\\Java\\jdk1.8.0_65"/>
</vmType>
</vmSettings>
As you may notice by looking at the above configuration, the default VM has the vm id "1538040823497", which is named jdk1.8.0_65, and resides in C\:\\Program Files\\Java\\jdk1.8.0_65.
This VM is correctly registered as Workspace Default in Eclipse Preferences, Java/Installed JREs, is marked as a "perfect match" within the Execution Environment JAVASE-1.8.
I cannot see anything why Maven Eclipse Plugin considers
org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7 as the correct choice, and not JAVASE-1.8.
I already deleted all JREs and registered them newly.
Now there's exactly one 1.6, 1.7 and 1.8 Environment, each with a "perfect match", and 1.8 is checked as default (as you can see above).
I have to manually correct the project each time I generated it (Edit Build Path, change JRE library from 7 to 8), since all files using Java 8 features like streams or lambda functions signal compiler errors unless I assign the correct JRE manually.
I already tried and manipulate org.eclipse.jdt.launching.prefs, redefine all JREs, pray, curse or ask an Ouija board, to no avail, always Java 7 is assigned by the eclipse plugin (version 2.10, by the way).
Any ideas, anyone?
In your pom file, try to use this:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
You may also reference this link:
https://dzone.com/articles/maven-eclipse-and-java-9
Or if all fails, try eclipse oxygen, a newer version (not the newest release but much better than Mars IMO) that has Maven Integration plugin pre-installed, all you need is to add a m2e-connector plugin.
Two different maven Java projects (let's call them ProjectA and ProjectB) depend on the same library (also a maven Java project, all three projects are self-written). ProjectA needs the library to be compiled for Java 1.7, ProjectB for 1.8. So far I had the following configuration in my library's pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
Installing the library like this then allows me to build ProjectB but not ProjectA, as and are both set to 1.8. I can change those two fields to 1.7 to allow ProjectA to be built but not B.
I want to do proper version control, automated builds, etc. and hence can't always change the lib's source/target version before building a project. Maintaining two library release branches, so solving the issue via the version control system, is also annoying and does not seem elegant (that's my current approach which I'd like to change).
If I replace the version with a variable (e.g. ${jdk.version}) and use the command line flag -Djdk.version=1.7 when installing the lib ProjectA will, for some reason, still not build, claiming the lib is targeted at 1.8. So apparently this is not equivalent to manually putting the 1.7 into the pom.xml file.
How can one solve this problem elegantly? Why will maven/Java not properly target the library at 1.7 if I try to set the corresponding property via the command line?
I'm using the latest JDK and everywhere from project creation to now everything is set to Java8 or SDK 8.
Still, intelliJ gives me this issue:
The red lamp tells me to change to Java7.
This is my project settings:
and this is the Modules section:
As you can see; I specifically changed it from the SDK default to java 8 when I got the error, but no result.
The compiler settings look like this:
I'm on a macbook and the intelliJ is the community version. Does anyone know why this is happening and how I fix it?
Try to run the project, if this is your error message:
Then I suggest you have a little look into your pom-file.
This project was built using the intelliJ maven project setting, and it was missing this lovely line of code:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
IntelliJ doesn't (at least in my case) generate the version in the pom (despite that I picked all the settings for it).
I tried specifying the compiler version in the plugin too, to no avail. Have you tried invalidating the cache? It's File -> Invalidate Caches/Restart.... I would probably restart as well for good measure.
We have a Maven based Android build, and we just made the switch from JDK 6 to 7.
This came with its share of IntelliJ problems though. What happens is that every time it detects a change in the POM, and reimports/refreshes the project, it returns to selecting the old "Module SDK", the one that's configured to use Java 6:
Even if I manually delete these SDKs from the "Platform Settings" dialog, they keep reappearing as "Maven Android API 19 Platform (N)" where N is the number used to disambiguate it from all the other (identical) SDKs.
I should mention that we do specify in the POM that Java 7 is targeted. I tried to set both the compiler plugin language level, and the maven.compiler.* properties (not sure if that accomplishes the same thing or not), without luck:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
shouldn't IntelliJ pick that up and always configure the project to use a Java 7 SDK? Am I missing something?
I noticed that the problem disappears when I remove any references to 1.6 SDKs entirely in IntelliJ. Not surprising I guess, but also not viable since I have other projects that still rely on the presence of a Java 6 SDK.
I encountered a very similar issue with Maven projects I'd created using IntelliJ (version 14.x in my case). I'd configured IntelliJ to use JDK 8 in the Project Settings but the IDE continued to highlight issues in my code (e.g. complaining about the usage of #Override).
It turns out that the Maven Settings take precedence here, which in my case defaulted to JDK 1.5 (hence the IDE redlines). Changing the settings here does resolve the issue, but only temporarily because they revert back whenever the Maven projects are reimported, or when IntelliJ is restarted.
The permanent fix is to explicitly declared the JDK version in your Maven pom file, as explained in these items.
stop IntelliJ IDEA to switch java language level everytime the pom is reloaded (or change the default project language level) by #vikingsteve
IDEA: javac: source release 1.7 requires target release 1.7 by #bacchus
Here's what they've said you need to add to your pom.xml file.
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
These settings get reflected in the Maven Settings in the IDE and resolved the issue for me.
It will pick up the jdk that you choose in project structure please change it there.
File > project structure > project setting > project > project sdk choose 1.7.
If 1.7 is not present go to
File > project structure > Platform setting > SDKs addd 1.7 there.
It's also important to note that you need to change the runner (jdk level) of your maven.
Maven > Runner > JRE
I've imported jfreechart-fse from here: https://github.com/jfree/jfreechart-fse
and I've imported this to eclipse as maven project.
After that, I have many problems, for example in class ChartPanel in org.jfree.chart paskage, eclipse doesn't see "implements" section, and notice
#Override
public void actionPerformed(ActionEvent event) {...}
as a problem. The same situation is in many other cases.
Can you tell what is wrong with that?
Change version of java to 1.7. It resolves most of errors (errors still appear only in test directory in package-info.java files). Maven can build project successfully.
In eclipse you can change java version in project properties in Java Compiler tab or in properties of JRE System Library in your project tree.
pom.xml doesn't declare java version for maven compiler plugin.
J2SE-1.5 is used by default, and Override anotation cannot be used for Interface implementation for this version.
Change Eclipse project configuration to use JavaSE-1.6, or fix pom.xml of project before importing:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>