无法使用maven编译java项目

2024-05-20

我正在尝试在 java 16.0.1 上使用 maven 构建 IntelliJ 项目,但它无法编译我的项目,尽管 IntelliJ 能够成功完成。在此之前,我使用maven编译了一个java 15项目,但我决定将所有内容更新到16.0.1,因为我的机器上不同版本的java完全混乱,就像我能够编译但不能运行生成的.jar文件一样等等。
mvn compile output:

[ERROR] Error executing Maven.
[ERROR] java.lang.IllegalStateException: Unable to load cache item
[ERROR] Caused by: Unable to load cache item
[ERROR] Caused by: Could not initialize class com.google.inject.internal.cglib.core.$MethodWrapper

这是我的pom.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<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>org.example</groupId>
    <artifactId>TaxiDB</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>16.0.1</release>
                </configuration>
            </plugin>
        </plugins>
    </build>

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

    <dependencies>
        ...
    </dependencies>
</project>

mvn -version output:

Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 16.0.1, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-16-oracle
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.8.0-50-generic", arch: "amd64", family: "unix"

java -verion output:

java version "16.0.1" 2021-04-20
Java(TM) SE Runtime Environment (build 16.0.1+9-24)
Java HotSpot(TM) 64-Bit Server VM (build 16.0.1+9-24, mixed mode, sharing)

问题是你的Maven版本太旧了。它与 JDK 16 不兼容。

尝试手动安装maven版本3.8.1:

https://maven.apache.org/install.html https://maven.apache.org/install.html

这将解决您的问题,而无需降级您的 JDK 版本。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法使用maven编译java项目 的相关文章

随机推荐