无法在 Maven 依赖管理中找到 jar
Unable to locate the jar in Maven Dependency Management
我有 2 个项目 testing.parent
和 testing.child
。
项目结构如下:
他们各自的pom如下:
testing.parent
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>testing.group</groupId>
<artifactId>testing.parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>testing.parent</name>
<url>http://maven.apache.org</url>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
</dependencyManagement>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
testing.child
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>testing.group</groupId>
<artifactId>testing.child</artifactId>
<version>1.1</version>
<packaging>jar</packaging>
<name>testing.child</name>
<url>http://maven.apache.org</url>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>testing.group</groupId>
<artifactId>testing.parent</artifactId>
<version>1.0</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
为了测试 dependency management
我尝试 import
将 log4j
jar 添加到 child
项目,但该 jar 在子项目中仍然不可用。这是导入罐子的正确方法吗?
Is this the correct way to import the jars?
是,在childpom.xml
的dependency
部分包含log4j。
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version> <!-- version is optional when using dependency management -->
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
此外,请务必参考 child 中的 parent
,为此在 child pom.xml
中包含以下内容:
<parent>
<artifactId>testing.parent</artifactId>
<groupId>testing.group</groupId>
<version>1.0</version>
</parent>
确保 parent pom.xml
中的引用与
相似
<modules>
<module>testing.child</module>
</modules>
如果将以下部分添加到子 pom.xml 文件中,则不需要通过子 pom.xml 单独导入 lof4j 依赖项。
<parent>
<artifactId>testing.parent</artifactId>
<groupId>testing.group</groupId>
<version>1.0</version>
</parent>
我有 2 个项目 testing.parent
和 testing.child
。
项目结构如下:
testing.parent
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>testing.group</groupId>
<artifactId>testing.parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>testing.parent</name>
<url>http://maven.apache.org</url>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
</dependencyManagement>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
testing.child
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>testing.group</groupId>
<artifactId>testing.child</artifactId>
<version>1.1</version>
<packaging>jar</packaging>
<name>testing.child</name>
<url>http://maven.apache.org</url>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>testing.group</groupId>
<artifactId>testing.parent</artifactId>
<version>1.0</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
为了测试 dependency management
我尝试 import
将 log4j
jar 添加到 child
项目,但该 jar 在子项目中仍然不可用。这是导入罐子的正确方法吗?
Is this the correct way to import the jars?
是,在childpom.xml
的dependency
部分包含log4j。
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version> <!-- version is optional when using dependency management -->
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
此外,请务必参考 child 中的 parent
,为此在 child pom.xml
中包含以下内容:
<parent>
<artifactId>testing.parent</artifactId>
<groupId>testing.group</groupId>
<version>1.0</version>
</parent>
确保 parent pom.xml
中的引用与
<modules>
<module>testing.child</module>
</modules>
如果将以下部分添加到子 pom.xml 文件中,则不需要通过子 pom.xml 单独导入 lof4j 依赖项。
<parent>
<artifactId>testing.parent</artifactId>
<groupId>testing.group</groupId>
<version>1.0</version>
</parent>