【发布时间】:2019-08-20 10:00:03
【问题描述】:
我有一个基于 NetBeans maven 的项目,我想从 Java 1.8 切换到 12,但我无法编译它。
经过多次尝试,我决定从头开始,创建一个非常简单的项目来了解如何进行此更改。
嗯,我试过了,也编译不了这个简单的项目。
谁能解释我做错了什么?
序言
NetBeans:10.0
JAVA_HOME: C:\Program Files\Java\jdk-12(我也试过9、10、11)
项目创建
- 使用窗口创建项目(第一个 TopComponent)
- 我将 JDK 版本从 11(NetBeans 10.0 中的默认值)更改为 12
-
这是自动生成的带有 javax.annotation-api 依赖关系的 POM
<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> <parent> <groupId>it.prj</groupId> <artifactId>Project-parent</artifactId> <version>2.9</version> </parent> <artifactId>Project-source</artifactId> <packaging>nbm</packaging> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>nbm-maven-plugin</artifactId> <extensions>true</extensions> <configuration> <useOSGiDependencies>true</useOSGiDependencies> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <useDefaultManifestFile>true</useDefaultManifestFile> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-netbeans-api-annotations-common</artifactId> <version>${netbeans.version}</version> </dependency> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-openide-windows</artifactId> <version>${netbeans.version}</version> </dependency> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-openide-util</artifactId> <version>${netbeans.version}</version> </dependency> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-openide-util-ui</artifactId> <version>${netbeans.version}</version> </dependency> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-openide-util-lookup</artifactId> <version>${netbeans.version}</version> </dependency> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-openide-awt</artifactId> <version>${netbeans.version}</version> </dependency> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-netbeans-modules-settings</artifactId> <version>${netbeans.version}</version> </dependency> <dependency> <groupId>javax.annotation</groupId> <artifactId>javax.annotation-api</artifactId> <version>1.3.2</version> <type>jar</type> </dependency> </dependencies> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> 然后我开始 Clean & Build > SUCCESS
我将 Java 版本从 1.7 更改为 12
这会将相关的插件添加到 POM 中
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>12</source>
<target>12</target>
</configuration>
</plugin>
-
更新版本字段,变成:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> <configuration> <source>12</source> <target>12</target> </configuration> </plugin> -
然后我重新启动 Clean & Build > FAILED
cd D:\Project\Project-source; "JAVA_HOME=C:\\Program Files\\Java\\jdk-12" "M2_HOME=C:\\Program Files\\apache-maven-3.6.0" cmd /c "\"\"C:\\Program Files\\apache-maven-3.6.0\\bin\\mvn.cmd\" -Dmaven.ext.class.path=\"C:\\Program Files\\Netbeans 10.0\\java\\maven-nblib\\netbeans-eventspy.jar\" -Dfile.encoding=UTF-8 clean install\""Building Project-source 2.9
--- maven-clean-plugin:2.5:clean (default-clean) @ Project-source ---
删除 D:\Project\Project-source\target
--- maven-resources-plugin:3.1.0:resources (default-resources) @ Project-source ---
Using 'UTF-8' encoding to copy filtered resources.
Copying 1 resource
--- maven-compiler-plugin:3.8.0:compile (default-compile) @ Project-source ---
Changes detected - recompiling the module!
Compiling 1 source file to D:\Project\Project-source\target\classes
--- nbm-maven-plugin:4.1:manifest (default-manifest) @ Project-source ---
NBM Plugin generates manifest
Adding OSGi bundle dependency - javax.annotation:javax.annotation-api
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Failed to execute goal org.codehaus.mojo:nbm-maven-plugin:4.1:manifest (default-manifest) on project Project-source:
Execution default-manifest of goal org.codehaus.mojo:nbm-maven-plugin:4.1:manifest failed.: IllegalArgumentException
编辑
- 我已尝试按照建议删除 nbm-maven-plugin,但这改变了 Project 的结构,我不知道如何重新包含此模块
【问题讨论】:
-
nbm-maven-plugin失败,不是编译。暂时从您的构建中删除nbm-maven-plugin,看看它是否有效。
标签: java maven java-8 maven-plugin maven-compiler-plugin