developer tip

Java 버전은 Maven 업데이트 후 자동으로 Java 1.5로 변경됩니다.

optionbox 2020. 8. 16. 20:10
반응형

Java 버전은 Maven 업데이트 후 자동으로 Java 1.5로 변경됩니다.


이클립스를 IDE로 사용하고 있습니다. 프로젝트를 마우스 오른쪽 버튼으로 클릭 한 다음 maven을 클릭하면 Java 버전 변경을 1.5로 업데이트합니다. 지금까지 수행 한 작업은 다음과 같습니다. 여기에 나열된 모든 단계를 따랐습니다.

http://qussay.com/2013/09/13/solving-dynamic-web-module-3-0-requires-java-1-6-or-newer-in-maven-projects/

  1. "Java 빌드 경로"를 "workspace default jre 1.8.0_25"로 변경했습니다.
  2. 그런 다음 "자바 컴파일러"를 1.8로 변경했습니다.
  3. 그런 다음 "project facets"> java> 1.8을 변경했습니다.
  4. pom.xml 자바 버전이 1.8로 변경되었습니다.
    <build>
        <plugins>
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.1.3.v20140225</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugin</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

이 모든 후에 "Maven 업데이트"를 클릭하면 Java 버전이 자동으로 1.5로 변경됩니다. 또한 위의 단계에서 처음 두 단계의 버전도 자동으로 1.5로 변경됩니다. 이 문제를 어떻게 해결할 수 있습니까?


pom.xml파일을 열고 다음 행을 추가하십시오.

<properties>
   <maven.compiler.source>1.8</maven.compiler.source>
   <maven.compiler.target>1.8</maven.compiler.target>
</properties>

1.8현재 JDK / JRE의 Java 버전은 어디에 있습니까 ? 이를 수행하는 또 다른 방법은 as를 추가하는 것 <build>입니다.maven-compile-plugin

<build>
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.2</version> <!-- or whatever current version -->
    <configuration>
      <source>1.8</source>
      <target>1.8</target>
    </configuration>
  </plugin>
</plugins>
</build>

편집하다

Java 버전 9 이상에서 작동하는 방법을 찾고 있다면 여기 에서 @JDelorean의 답변을 살펴보고 그에게 찬성 투표 를 제공하는 것을 잊지 마십시오 :)


Java 9를 설치할 때 동일한 문제가 발생했습니다. 내 프로젝트는 J2SE-1.5 Execution Environment로 기본 설정됩니다. 이상하게도 Java 9 준수 수준은 이전 버전 인 "1.8"과 같이 참조되지 않고 "9"로 참조됩니다. 따라서 내 속성과 Maven 컴파일러 플러그인 구성을 적절하게 제공해야했습니다.

<properties>
    <maven.compiler.source>9</maven.compiler.source>
    <maven.compiler.target>9</maven.compiler.target>
</properties>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>9</source>
        <target>9</target>
    </configuration>
</plugin>

이것은 문제를 해결 한 것 같습니다.


The root-cause of this issue is that if for any reason Eclipse's cannot resolve a valid value for the maven.compiler.source property when generating/updating the .classpath file from the pom, it will simply default to using org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5.

As expertly answered by @jorge-campos, there are multiple ways to set that property.

However, Jorge's answer didn't appear to work for me. Here were my settings:

<properties>
    <javaVersion>1.8</javaVersion>
    <maven.compiler.source>${java.version}</maven.compiler.source>
    <maven.compiler.target>${java.version}</maven.compiler.target>
</properties>

...

Exactly. ${java.version} is never going to resolve to the (completely different) property javaVersion and Eclipse ignored the property and used the default.

Which brings me back to the "for any reason" part I opened with; developer stupidity can be one of those reasons.


Add this lines to your pom.xml, then right click your JRE System Library -> Properties -> Set your correct execution environment to Java 1.8 or version you want to set.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.2</version> <!-- or whatever current version -->
    <configuration>
      <source>1.8</source>
      <target>1.8</target>
    </configuration>
  </plugin> 

I had this problem. In my case the <properties> tag & nested tags Jorge Campos mentions above were in the wrong place. If I put them between the <hostversion> and <dependencies> tags in the pom.xml file, then this behaviour stopped.

That can be picked up in Eclipse if validation of these files is switched on.


I encounter similar issue on one of my team mate machine. He was using old version of Eclipse, I believe it he was using Keppler. Project after being updated change JRE version to 1.5.

Simple updating Eclipse to latest version solve this problem.


In my case (old JBoss Developer Studio), the issue was the JRE environments did not include 1.8 (only 1.7). When I switched the maven-compiler-plugin version to 1.7 and did maven update project, it updated the Eclipse JRE system library to 1.7. enter image description here

So the solution is to either get a newer IDE version that includes a built-in JRE environment that is 1.8 or later, or try to install it manually (see https://stackoverflow.com/a/35204314)


I allow myself to update that subject with Java 11.

I have installed OpenJDK11 on my computer, and I wanted to use it in an app.

I had trouble because Eclipse would always change my JRE to JavaSE-1.5 when I updated my project with Maven.

I had set everything as you said, but I was always directly selecting in my Java Build Path "java-11-openjdk.x86_64" as one of my Alternante JRE. I fixed my problem by selecting in "Execution environment" JavaSE-10 (but you have to double click on it and then choose as a compatible JRE your OpenJDK11 version) as shown on the picture. Execution environment setup

The project will use Java 11 thanks to that (picture) but you have to write 10 for the java-version in the pom.xml and also set java 10 on the Project Facets.


I've resolved the issue installing the eclipse update "JAVA 12" from the market. It makes my eclipse pass from Kepler to Luna.

After that, i have been able to set 1.8 as standard JDK, fixing the "maven update" problem.


I changed Eclipse from kepler to neon and then updated my project by with Maven -> Update Project.

참고URL : https://stackoverflow.com/questions/28509928/java-version-automatically-change-to-java-1-5-after-maven-update

반응형