运行 IntelliJ IDEA 中的多模块项目出错
Getting error on running a multi-module project in IntelliJ IDEA
我正在 IntelliJ IDEA 旗舰版 2020.2 中制作一个 maven 项目。这是一个多模块项目。当我 运行 来自其中一个模块的 class 时,我得到一个错误,但是如果我 运行 来自打包的 jar,它 运行 没问题。这是应用程序的结构:
C:.
| pom.xml
|
+---DatabaseTier
| | pom.xml
| |
| +---src
| | \---main
| | +---java
| | | | module-info.java
| | | |
| | | \---org
| | | \---Geek8080
| | | | DatabaseTest.java
| | | |
| | | \---service
| | | \---database
| | | | Database.java
| | | |
| | | \---entities
| | | JournalPage.java
| | |
| | \---resources
| | log4j2.xml
| | table.sql
| |
| \---target
| +---classes
| | | log4j2.xml
| | | module-info.class
| | | table.sql
| | |
| | \---org
| | \---Geek8080
| | | DatabaseTest.class
| | |
| | \---service
| | \---database
| | | Database.class
| | |
| | \---entities
| | JournalPage.class
| |
| \---generated-sources
| \---annotations
\---Reports
| pom.xml
|
+---src
| +---main
| | +---java
| | | | module-info.java
| | | |
| | | \---org
| | | \---Geek8080
| | | | ReportTest.java
| | | |
| | | \---service
| | | \---report
| | | ExcelReports.java
| | | PDFReports.java
| | |
| | \---resources
| | log4j2.xml
| | MTCORSVA.TTF
| |
| \---test
| \---java
\---target
+---classes
| | log4j2.xml
| | module-info.class
| | MTCORSVA.TTF
| |
| \---org
| \---Geek8080
| | ReportTest.class
| |
| \---service
| \---report
| ExcelReports.class
| PDFReports.class
|
\---generated-sources
\---annotations
这是主要的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.Geek8080</groupId>
<artifactId>Journal</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<modules>
<module>DatabaseTier</module>
<module>Reports</module>
</modules>
<name>Journal Daily</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.13.3</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.13.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
DatabaseTier 模块中的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">
<parent>
<artifactId>Journal</artifactId>
<groupId>org.Geek8080</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>DatabaseTier</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.15.2.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>org.Geek8080.DatabaseTest</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
报告模块中的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">
<parent>
<artifactId>Journal</artifactId>
<groupId>org.Geek8080</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>Reports</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.Geek8080</groupId>
<artifactId>DatabaseTier</artifactId>
<version>1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.21</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>org.Geek8080.ReportTest</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
这是我遇到的错误:
Error occurred during initialization of boot layer
java.lang.LayerInstantiationException: Package org.Geek8080 in both
module Reports and module DatabaseTier
Process finished with exit code 1
不言自明
Package org.Geek8080
in both module Reports
and module DatabaseTier
这样有了模块系统和模块路径上的显式模块,没有两个模块可以导出相同的包。鉴于朝着可靠的配置和更好的可访问性迈进,带来了这一变化。有关这些概念的更多信息,请参阅 The State of the Module System。
作为解决方案,您可以将这些模块中的包分别重命名为 org.report.Geek8080
和 org.database.Geek8080
。
我正在 IntelliJ IDEA 旗舰版 2020.2 中制作一个 maven 项目。这是一个多模块项目。当我 运行 来自其中一个模块的 class 时,我得到一个错误,但是如果我 运行 来自打包的 jar,它 运行 没问题。这是应用程序的结构:
C:.
| pom.xml
|
+---DatabaseTier
| | pom.xml
| |
| +---src
| | \---main
| | +---java
| | | | module-info.java
| | | |
| | | \---org
| | | \---Geek8080
| | | | DatabaseTest.java
| | | |
| | | \---service
| | | \---database
| | | | Database.java
| | | |
| | | \---entities
| | | JournalPage.java
| | |
| | \---resources
| | log4j2.xml
| | table.sql
| |
| \---target
| +---classes
| | | log4j2.xml
| | | module-info.class
| | | table.sql
| | |
| | \---org
| | \---Geek8080
| | | DatabaseTest.class
| | |
| | \---service
| | \---database
| | | Database.class
| | |
| | \---entities
| | JournalPage.class
| |
| \---generated-sources
| \---annotations
\---Reports
| pom.xml
|
+---src
| +---main
| | +---java
| | | | module-info.java
| | | |
| | | \---org
| | | \---Geek8080
| | | | ReportTest.java
| | | |
| | | \---service
| | | \---report
| | | ExcelReports.java
| | | PDFReports.java
| | |
| | \---resources
| | log4j2.xml
| | MTCORSVA.TTF
| |
| \---test
| \---java
\---target
+---classes
| | log4j2.xml
| | module-info.class
| | MTCORSVA.TTF
| |
| \---org
| \---Geek8080
| | ReportTest.class
| |
| \---service
| \---report
| ExcelReports.class
| PDFReports.class
|
\---generated-sources
\---annotations
这是主要的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.Geek8080</groupId>
<artifactId>Journal</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<modules>
<module>DatabaseTier</module>
<module>Reports</module>
</modules>
<name>Journal Daily</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.13.3</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.13.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
DatabaseTier 模块中的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">
<parent>
<artifactId>Journal</artifactId>
<groupId>org.Geek8080</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>DatabaseTier</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.15.2.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>org.Geek8080.DatabaseTest</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
报告模块中的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">
<parent>
<artifactId>Journal</artifactId>
<groupId>org.Geek8080</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>Reports</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.Geek8080</groupId>
<artifactId>DatabaseTier</artifactId>
<version>1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.21</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>org.Geek8080.ReportTest</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
这是我遇到的错误:
Error occurred during initialization of boot layer java.lang.LayerInstantiationException: Package org.Geek8080 in both module Reports and module DatabaseTier
Process finished with exit code 1
不言自明
Package
org.Geek8080
in both moduleReports
and moduleDatabaseTier
这样有了模块系统和模块路径上的显式模块,没有两个模块可以导出相同的包。鉴于朝着可靠的配置和更好的可访问性迈进,带来了这一变化。有关这些概念的更多信息,请参阅 The State of the Module System。
作为解决方案,您可以将这些模块中的包分别重命名为 org.report.Geek8080
和 org.database.Geek8080
。