Java 无法在Maven依赖项管理中找到jar
我有两个项目Java 无法在Maven依赖项管理中找到jar,java,maven,dependency-management,maven-dependency,Java,Maven,Dependency Management,Maven Dependency,我有两个项目testing.parent和testing.child。 项目结构如下: 他们各自的POM如下所示: 测试。家长 <project> <modelVersion>4.0.0</modelVersion> <groupId>testing.group</groupId> <artifactId>testing.parent</artifactId> <versi
testing.parent
和testing.child
。
项目结构如下:
他们各自的POM如下所示:
测试。家长
<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>
4.0.0
测试组
测试父母
1
聚甲醛
测试父母
http://maven.apache.org
log4j
log4j
1.2.17
UTF-8
朱尼特
朱尼特
3.8.1
测试
测试。儿童
<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>
4.0.0
测试组
测试儿童
1.1
罐子
测试儿童
http://maven.apache.org
测试组
测试父母
1
进口
聚甲醛
UTF-8
朱尼特
朱尼特
3.8.1
测试
为了测试依赖项管理
,我尝试将导入log4j
jar到子项目
中,但子项目中仍然没有jar。这是进口罐子的正确方法吗
这是进口罐子的正确方法吗
是的,将log4j包含在子pom.xml
的依赖项
部分中
<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>
确保父pom.xml
as中的类似引用
<modules>
<module>testing.child</module>
</modules>
测试儿童
如果将下面的部分添加到child pom.xml文件中,则不需要通过child pom.xml单独导入lof4j依赖项
<parent>
<artifactId>testing.parent</artifactId>
<groupId>testing.group</groupId>
<version>1.0</version>
</parent>
测试父母
测试组
1
您看过这个链接了吗?如果我特别需要在依赖项部分单独包含log4j,那么拥有依赖项管理部分有什么用呢?我本可以做同样的事情,而不需要父项、依赖项管理等的所有附加部分,直接包括log4j。依赖项管理部分主要是以集中的方式控制依赖项的版本。您可以在文档中阅读更多关于它的内容,因此总结一下,在我的例子中,仅在依赖项管理中导入父依赖项不会使log4jjar在child中可用。我还必须将其包含在依赖项部分,对吗?@ghostrider是的,除非它通过某种传递依赖项可用。我知道这一点。我想检查依赖关系管理的好处。对于依赖关系管理来说,这是一个两步的过程,对吗?
<parent>
<artifactId>testing.parent</artifactId>
<groupId>testing.group</groupId>
<version>1.0</version>
</parent>