我有一个小测试项目,包含2个文件:
pom.xml
<?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>test</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20210307</version>
</dependency>
</dependencies>
</project>和src/main/java/module-info.java
module org.example.test {
requires org.json;
}当我用Temurin 17编译时:
openjdk version "17" 2021-09-14
OpenJDK Runtime Environment Temurin-17+35 (build 17+35)
OpenJDK 64-Bit Server VM Temurin-17+35 (build 17+35, mixed mode, sharing)而Maven 3.6.3附带了IntelliJ IDEA,我得到了这个错误:
src/main/java/module-info.java:[2,17] module not found: org.jsonjson-20210307.jar文件在META-INF/MANIFEST.MF中包含这一行
Automatic-Module-Name: org.json我还需要做什么才能在Maven中使用JPMS?
发布于 2021-10-13 19:57:41
如果您运行mvn help:effective-pom,您会注意到该项目使用了可能有点过时的maven编译器版本。显式地尝试使用更新的版本,看看它如何改变事物:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version> <!-- current version -->
</plugin>
</plugins>
</pluginManagement>
</build>https://stackoverflow.com/questions/69561279
复制相似问题