pom.xml 파일에서 Java 컴파일러 버전을 어떻게 지정합니까?
약 2000 줄 이상이있는 netbeans에 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
Java 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>
당신이 나를 도울 수 있다면 좋을 것입니다.
<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
아, Java 1.3.x를 사용하지 마십시오. 현재 버전은 Java 1.7.x 또는 1.8.x입니다.
maven-compiler-plugin pom.xml의 플러그인 계층 구조 종속성에 이미 있습니다. 유효 POM을 체크인하십시오.
간단히 말해 다음과 같은 속성을 사용할 수 있습니다.
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
maven 3.2.5를 사용하고 있습니다.
일반적으로 source버전 만 평가하고 싶지는 않지만 ( javac -source 1.8예 :) 버전 source과 가치를 모두 평가하려고합니다 . Java 9부터는 정보를 전달할 수있는 방법과 교차 컴파일 호환성 ( )을 위한보다 강력한 방법이 있습니다. 명령 을 래핑하는 Maven은 이러한 모든 JVM 표준 옵션을 전달하는 여러 가지 방법을 제공합니다.targetjavac -source 1.8 -target 1.8javac -release 9javac
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>
받는있어서 동등 컴파일러 플러그인 메이븐 문서 사람 <source>및 <target>속성 컴파일러 구성 요소를 사용 maven.compiler.source하고 maven.compiler.target그들이 정의되어 있으면.
-sourceJava 컴파일러 의 인수
기본값은1.6입니다.
사용자 속성은 다음과 같습니다maven.compiler.source.
-targetJava 컴파일러 의 인수
기본값은1.6입니다.
사용자 속성은 다음과 같습니다maven.compiler.target.
기본 값 소개 source하고 target, 참고 이후 3.8.0받는다는 컴파일러는 기본 값에서 변경 1.5을1.6 .
maven-compiler-plugin 3.6에서 Java 버전을 지정하는 새로운 방법이 있습니다
<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사용중인 기본 버전이 최근의 충분한 버전에 의존하지 않기 때문에 현재 마지막 버전 으로는 충분 하지 않습니다.
Maven release인수는 다음을 전달합니다 release. Java 9에서 전달할 수 있는 새로운 JVM 표준 옵션 입니다.
특정 VM 버전에 대해 공개되고 지원되며 문서화 된 API에 대해 컴파일합니다.
이 방법은 source, target및 bootstrapJVM 옵션에 동일한 버전을 지정하는 표준 방법을 제공합니다 .
를 지정하는 bootstrap것은 교차 컴파일에 대한 좋은 습관이며 교차 컴파일을 수행하지 않아도 손상되지 않습니다.
JDK 버전을 지정하는 가장 좋은 방법은 무엇입니까?
Java 8 이하의 경우 :
나도 maven.compiler.source/ maven.compiler.target등록 또는 사용이 maven-compiler-plugin낫다. 마지막으로 두 가지 방법이 동일한 속성과 동일한 메커니즘 인 maven core 컴파일러 플러그인에 의존하기 때문에 사실에는 아무런 변화가 없습니다.
컴파일러 플러그인에서 Java 버전 이외의 다른 속성이나 동작을 지정할 필요가없는 경우이 방법을 사용하면보다 간결하므로이 방법을 사용하는 것이 좋습니다.
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
자바 9에서 :
release인수 (세 번째 점)를 사용하면 동일한 버전을 사용하려는 경우 강력하게 고려하는 방법 source과 target.
나는 일식 네온 간단한 메이븐 자바 프로젝트에서 같은 문제에 직면했다.
하지만 아래의 세부 사항을 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>
프로젝트> maven> 프로젝트 업데이트 (확인 된 강제 업데이트)를 마우스 오른쪽 버튼으로 클릭 한 후
프로젝트에서 오류를 표시하도록 해결
도움이 되길 바랍니다.
탄 스크
<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>
'IT story' 카테고리의 다른 글
| PHP에서 문자열을 정수로 변환하는 가장 빠른 방법 (0) | 2020.04.06 |
|---|---|
| 사용중인 NumPy 버전을 어떻게 확인합니까? (0) | 2020.04.05 |
| SQL Server에 데이터베이스가 있는지 확인하는 방법 (0) | 2020.04.05 |
| 여러 개의 AsyncTask를 동시에 실행하는 것은 불가능합니까? (0) | 2020.04.05 |
| 숫자 및 범위가있는 AngularJS For 루프 (0) | 2020.04.05 |