我在netbeans上写了一个maven代码,它有大约2000多行.当我在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 …Run Code Online (Sandbox Code Playgroud) 运行我们的Maven构建时,我的团队成员在执行时会收到此错误.但是,当我们java -version从她的命令行运行时,它表示Java 1.6.0_26.Maven正在使用Java 5,这个错误显然似乎在尖叫.
我如何找出并更改Maven正在使用的Java版本?
3个可能重要的说明:
将Java 11指定为要在Spring(或Spring Boot)pom.xml文件中使用的版本的正确方法是什么?
即,我需要java.version在pom 的属性中添加什么值?
1.8正如文档所示,对于Java 8,我们使用的是Java 9 1.9。
我不确定Java 11是否会1.11(尽管似乎不太可能),并且我已经看到它仅11在使用时指定maven-compiler-plugin,但是我没有使用编译器插件。
例如
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我到处搜索,找不到答案,因为我阅读的几乎所有文档以及与Java版本有关的博客文章仅显示版本8或版本9。
那我该怎么用呢?1.11还是只是11?
我尝试了两者,但我的Web服务器似乎可以正确启动并正确编译(IntelliJ显示Information:javac 11.0.2 was used to compile java sources),但是我并不完全相信更改java.version值可以完成任何事情,因为我可以将其设置为eg 100并且一切正常。
我能找到的唯一相关问题是:与Java 11兼容的最低Spring版本,由于使用OpenJDK 11 迁移到JDK 11和Spring 4.3.x 之后,由于Hibernate错误而导致Spring Boot失败,但是它们并没有真正引起人们的注意。
我有两个关于maven.compiler.release-tag 的问题
我想更换
<properties>
<maven.compiler.source>12</maven.compiler.source>
<maven.compiler.target>12</maven.compiler.target>
</properties>
Run Code Online (Sandbox Code Playgroud)
到
<properties>
<maven.compiler.release>12</maven.compiler.release>
</properties>
Run Code Online (Sandbox Code Playgroud)
如果我使用<maven.compiler.release>-property,是否还必须在插件中设置发布标签?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<!-- do I need that ? -->
<release>12</release>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
根据https://www.baeldung.com/maven-java-version,它被设置为两者。
如果我使用maven.compiler.release而不是maven.compiler.sourceand maven.compiler.target,那么-bootclasspath也会被设置并且会进行交叉编译。这是什么意思?使用 set 的编译文件大小-bootclasspath会更大还是编译需要更多时间?
我有:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Run Code Online (Sandbox Code Playgroud)
然而我宣布:
public enum DirectoryWatchService {
INSTANCE;
private java.util.Optional<String> test;
private java.nio.file.Files files;
}
Run Code Online (Sandbox Code Playgroud)
Eclipse没有打扰.IntelliJ也不是.即使是Maven也不会打扰.我甚至可以做一个mvn清洁包.在没有任何警告的情况下构建糟糕的东西.
在 maven 属性中指定 java 版本时可能有两个不同的属性:
<properties>
<java.version>7</java.version>
</properties>
Run Code Online (Sandbox Code Playgroud)
和
<properties>
<maven.compiler.source>7</maven.compiler.source>
<maven.compiler.target>7</maven.compiler.target>
</properties>
Run Code Online (Sandbox Code Playgroud)
有什么区别以及何时使用什么?
我可能会为遗留项目做一些交叉编译,我注意到最近的 JDK 仅限于某些特定版本的source,target和releaseJVM 参数。
如何获得这些参数的支持版本?
当我尝试运行 Maven 构建时,我遇到了构建错误。我创建了一个简单的 Java 项目,其中包含 lambda 函数,因此我得到了
[ERROR] (...) lambda expressions are not supported in -source 1.5
[ERROR] (use -source 8 or higher to enable lambda expressions)
Run Code Online (Sandbox Code Playgroud)
我的 Java 版本是 1.8.0_172,我的 Maven 版本是 3.6.0。
我正在更新 Spigot (Minecraft) 插件,最新版本的 Spigot 需要 Java 16。在我的 pom 中,我将 maven 编译器插件目标更改为 16,源代码仍然是 1.8。现在我收到以下错误:
Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:3.2.4:shade (default) on project Plugin: Error creating shaded jar: Problem shading JAR C:\Users\Trent\workspace\Stocks\Plugin\target\Plugin-1.0-SNAPSHOT.jar entry com/tchristofferson/stocks/commands/StockbrokerCommand.class: java.lang.IllegalArgumentException: Unsupported class file major version 60
Run Code Online (Sandbox Code Playgroud)
pom:
<?xml version="1.0" encoding="UTF-8"?>
Run Code Online (Sandbox Code Playgroud)
4.0.0
<groupId>com.tchristofferson</groupId>
<artifactId>Stocks</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>API</module>
<module>Plugin</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>16</target>
<release>16</release>
</configuration>
</plugin>
</plugins>
</build>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
Run Code Online (Sandbox Code Playgroud) java ×8
maven ×8
pom.xml ×2
compilation ×1
eclipse ×1
java-8 ×1
javac ×1
lambda ×1
maven-plugin ×1
spring ×1
spring-boot ×1