How to force Maven to use the default Eclipse workspace JRE?

I use the Spring Tool Suite and m2e to convert some of our existing projects to Maven projects. This project uses jdk1.6.0_20, which is named [jdk1.6] in Eclipse. However, when I do the Maven β†’ Update project, it replaces this standard with the [JavaSE-1.6] standard. Although they seem to point to the same libraries, changing the name raises a bunch of exceptions, such as:

Access restriction: WindowsPopupMenuSeparatorUI type is not accessible due to the required library restriction C: \ Program Files \ Java \ jdk1.6.0_20 \ JRE \ Lib \ rt.jar

My pom.xml has the following:

<plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> 

Is there a way to force Maven / m2e to use a standard JRE workspace instead of replacing it with a specific one in .classpath?

+4
source share
3 answers

It turned out that this was not like Maven. Instead, I changed the error to a warning in the Eclipse settings while I work with the owners of the violating code to fix the problems.

+1
source
  • Go to the "Customize build path" in the project and go to the "Libraries" tab.
  • Delete JRE Library
  • Click "Add Library ..." and select "Default Workspace JRE"

This will give you the current JRE and not indicate a specific JRE

+4
source

Adding the maven compiler plugin to your maven pom command to use this 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 both jre and jdk are installed on your system (for a specific version of java), maven may select jre and then complain that it needs a JDK . This can happen after using Maven> Update Project in Eclipse.

To solve this problem, in Eclipse, right-click on the JRE System Library> Properties> Environments and select JavaSE-1.8. If your system has several compatible JREs, select the jdk1.8.x checkbox> OK> select JavaSE-1.8 (jdk1.8.x) as the runtime> OK

Now maven should choose Java version 1.8, and Eclipse will tell maven to use jdk1.8 as the standard JRE for this version of java.

+2
source

Source: https://habr.com/ru/post/1432990/


All Articles