programing

pom.xml 파일에서 Java 컴파일러 버전을 지정하는 방법은 무엇입니까?

randomtip 2022. 9. 8. 21:34
반응형

pom.xml 파일에서 Java 컴파일러 버전을 지정하는 방법은 무엇입니까?

저는 Netbeans로 약 2000줄 이상의 Maven 코드를 작성했습니다.Netbeans에서 컴파일하면 문제없지만 명령줄에서 실행할 경우 다음과 같은 오류가 발생합니다.

generics are not supported in -source 1.3
(use -source 5 or higher to enable generics)
        ArrayList<ArrayList<Integer>> list = new ArrayList<ArrayList<Integer>>();

generics are not supported in -source 1.3
(use -source 5 or higher to enable generics)
        HashSet<Double> resid_List = new HashSet<Double>(Arrays.asList(resid_val));

generics are not supported in -source 1.3
(use -source 5 or higher to enable generics)
        List<Integer> ind_ovlpList = new ArrayList<Integer>(Arrays.asList(ind_ovlp));

generics are not supported in -source 1.3
(use -source 5 or higher to enable generics)
public class ColumnComparator implements Comparator<double[]> {

annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
@Override

자바 1.3.1, 컴파일러 에러를 사용하려고 했지만 에러가 더 많이 발생하였습니다.수정해야 할 다른 게시물을 발견했습니다.pom.xml어떻게 하는지 모르겠어요.여기 제 것이 있습니다.pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.mycompany</groupId>
  <artifactId>mavenmain</artifactId>
   <version>1.0-SNAPSHOT</version>
   <packaging>jar</packaging>

   <name>mavenmain</name>
    <url>http://maven.apache.org</url>

   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

   <dependencies>
     <dependency>
       <groupId>junit</groupId>
        <artifactId>junit</artifactId>
       <version>3.8.1</version>
       <scope>test</scope>
     </dependency>
     <dependency>
        <groupId>gov.nist.math</groupId>
        <artifactId>jama</artifactId>
        <version>1.0.2</version>
     </dependency>
   </dependencies>
 </project>

네가 날 도와준다면 정말 좋을 거야!

이미 pom.xml의 플러그인 계층 의존관계에 존재합니다.Effective POM 체크인을 합니다.

즉, 다음과 같은 속성을 사용할 수 있습니다.

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

Maven 3.2.5를 사용하고 있습니다.

<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>(whatever version is current)</version>
        <configuration>
          <!-- or whatever version you use -->
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
    </plugins>
    [...]
  </build>
  [...]
</project>

maven 컴파일러 플러그인의 설정 페이지를 참조해 주세요.

http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html

아, 그리고 자바 1.3.x를 사용하지 마세요.현재 버전은 자바 11 또는 17입니다.

일반적으로 고객님은 고객님의 고객님께만 가치를 부여하고 싶지는 않습니다.source버전(javac -source 1.8예를 들어) 단, 두 가지 가치를 모두 중시하고 싶다.source및 그target버전(javac -source 1.8 -target 1.8예를 들어)를 참조해 주세요.
Java 9 에서는, 상호 컴파일 호환성을 위해서, 양쪽 모두의 정보를 보다 견고한 방법으로 전달할 수 있습니다.javac -release 9).
를 감싸는 메이븐javac명령어는 이러한 모든 JVM 표준 옵션을 전달하는 여러 방법을 제공합니다.

JDK 버전을 지정하는 방법

사용.maven-compiler-plugin또는maven.compiler.source/maven.compiler.target속성을 지정하다source및 그target동등합니다.

<plugins>
    <plugin>    
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
            <source>1.8</source>
            <target>1.8</target>
        </configuration>
    </plugin>
</plugins>

그리고.

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

컴파일러 플러그인의 Maven 문서에 따라 동등합니다.<source>및 그<target>컴파일러 설정의 요소는 속성을 사용합니다.maven.compiler.source그리고.maven.compiler.target정의되어 있는 경우.

원천

-sourceJava 컴파일러의 인수입니다.
기본값은 다음과 같습니다.1.6.
사용자 속성:maven.compiler.source.

타깃

-targetJava 컴파일러의 인수입니다.
기본값은 다음과 같습니다.1.6.
사용자 속성:maven.compiler.target.

기본값 정보source그리고.targetmaven 컴파일러 이후 기본값은 에서로 변경된 점에 주의해 주십시오.

<release>tag : Java 버전을 지정하는 새로운 방법maven-compiler-plugin 3.6

다음 인수를 사용할 수 있습니다.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
    <configuration>
        <release>9</release>
    </configuration>
</plugin>

사용자 속성만 선언할 수도 있습니다.maven.compiler.release:

<properties>
    <maven.compiler.release>9</maven.compiler.release>
</properties>

하지만 이 시간에는 마지막 것으로는 충분하지 않을 것입니다.maven-compiler-plugin사용하는 기본 버전은 충분한 최신 버전에 의존하지 않습니다.

★★★★★★★★★★★★★★★」release가 전하다releaseJava 9에 새로 추가된 JVM 표준 옵션인 JEP 247: 이전 플랫폼 버전을 위한 컴파일 옵션에 액세스할 수 있습니다.

특정 VM 버전에 대해 퍼블릭 API, 지원 API 및 문서화된 API를 기반으로 컴파일합니다.

하면 할 수 .source , . . . . . . . .targetbootstrapJVM 션 j
, 을 하면 됩니다.bootstrap교차 컴파일에 좋은 방법이며 교차 컴파일을 하지 않아도 문제가 되지 않습니다.

JDK 버전을 지정하는 가장 좋은 방법은 무엇입니까?

Java 8 이하

다 아니다.maven.compiler.source/maven.compiler.target속성 또는 사용maven-compiler-plugin 컴파일러 플러그인이라는 가 없습니다.최종적으로 두 가지 방법이 동일한 속성과 메커니즘인 maven 코어 컴파일러 플러그인에 의존하기 때문에 사실에는 변화가 없습니다.

컴파일러 플러그인에서 Java 버전 이외의 속성이나 동작을 지정할 필요가 없는 경우 이 방법을 사용하는 것이 보다 간결하기 때문에 더 적합합니다.

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

Java 9 이후

releaseargument(세 번째 는에 같은 입니다.sourcetarget.

나는 이클립스 네온 심플 메이븐 자바 프로젝트에서 같은 문제에 직면했다.

그러나 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>

project > maven > update project 우클릭 후 (force update on)

프로젝트에서 오류를 표시하도록 해결합니다.

도움이 되었으면 좋겠다

탄스크

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <fork>true</fork>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin> 

언급URL : https://stackoverflow.com/questions/16723533/how-do-you-specify-the-java-compiler-version-in-a-pom-xml-file

반응형