Maven工程子模块引用父pom.xml中的jar包
方式一:如果父pom中使用的是
<dependencies>....</dependencies>
这种方式,则子pom会自动使用pom中的jar包;
方式二:如果父pom使用
<dependencyManagement>
<dependencies>....</dependencies>
</dependencyManagement>
的方式,则子pom不会自动使用父pom中的jar包,这时如果子pom想使用的话,就要给出groupId和artifactId,无需给出version。
方式一比较容易理解,此处就不举例了。
方式二举例:父pom.xml使用的如下所示:
<!-- maven依赖 -->
<dependencyManagement>
<dependencies>
<!-- jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
</dependencies>
</dependencyManagement>
子maven中想要使用父maven中的jar包,需要写就要给出groupId和artifactId,无需给出version。如下图所示:
<dependencies>
<!-- servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
</dependency>
</dependencies>