评论

收藏

[Java] 如何使用eclipse搭建maven多module项目(构建父子项目)

编程语言 编程语言 发布于:2021-10-06 17:29 | 阅读数:397 | 评论:0

这篇文章主要介绍了如何使用eclipse搭建maven多module项目(构建父子项目) ,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
创建空maven项目
1、file–>new–>project…
DSC0000.png

2.next
DSC0001.jpg

3.next
DSC0002.jpg

4.finish
DSC0003.jpg

5.配置pom.xml
<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>pdd-shop</groupid> 
<artifactid>pdd-shop</artifactid> 
<version>0.0.1-snapshot</version> 
<packaging>pom</packaging> 
<name>pdd-shop</name> 
<url>http://maven.apache.org</url> 
<properties> 
<project.build.sourceencoding>utf-8</project.build.sourceencoding> 
<junit.version>4.11</junit.version> 
<spring.version>4.0.0.release</spring.version> 
</properties> 
<build> 
<finalname>pdd-shop</finalname> 
<plugins> 
<plugin> 
<groupid>org.apache.maven.plugins</groupid> 
<artifactid>maven-compiler-plugin</artifactid> 
<version>2.3.2</version> 
<configuration> 
<source>1.6</source> 
<target>1.6</target> 
<compilerversion>1.6</compilerversion> 
</configuration> 
</plugin> 
<!-- jar插件 --> 
<plugin> 
<groupid>org.apache.maven.plugins</groupid> 
<artifactid>maven-jar-plugin</artifactid> 
<version>2.5</version> 
<configuration> 
<archive> 
<manifest> 
<adddefaultimplementationentries>true</adddefaultimplementationentries> 
<adddefaultspecificationentries>true</adddefaultspecificationentries> 
</manifest> 
</archive> 
</configuration> 
</plugin> 
</plugins> 
</build> 
<dependencies> 
<dependency> 
<groupid>junit</groupid> 
<artifactid>junit</artifactid> 
<version>${junit.version}</version> 
</dependency> 
<!-- spring framework --> 
<dependency> 
<groupid>org.springframework</groupid> 
<artifactid>spring-web</artifactid> 
<version>${spring.version}</version> 
</dependency> 
<dependency> 
<groupid>org.springframework</groupid> 
<artifactid>spring-webmvc</artifactid> 
<version>${spring.version}</version> 
</dependency> 
<dependency> 
<groupid>commons-logging</groupid> 
<artifactid>commons-logging</artifactid> 
<version>1.2</version> 
</dependency> 
</dependencies> 
<modules> 
<module>pdd-shop-application</module> 
<module>pdd-shop-appweb</module> 
<module>pdd-shop-application-impl</module> 
</modules> 
</project>
创建module
创建java module
1、右键ppd-shop项目–>new–>project…
DSC0004.jpg

2.next
DSC0005.jpg

3.next
DSC0006.jpg

4.next
DSC0007.jpg

5.finish–>配置pom.xml
(主要把多余部分删除,junit只要在父工程的pom配置就可以了)
<?xml version="1.0"?>
<project xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/pom/4.0.0"
xmlns:xsi="http://www.w3.org/2001/xmlschema-instance">
<modelversion>4.0.0</modelversion>
<parent>
<artifactid>pdd-shop</artifactid>
<groupid>pdd-shop</groupid>
<version>0.0.1-snapshot</version>
</parent>
<groupid>pdd-shop</groupid>
<artifactid>pdd-shop-application</artifactid>
<version>0.0.1-snapshot</version>
<name>pdd-shop-application</name>
</project>
创建web module
1.与创建java module的1、2点一样;
2.next
DSC0008.jpg

3.把包名定义下~
4.右键pdd-shop-appweb项目–>properties–>project facets–>convert to faceted form..
这里选2.4版本的web工程是因为楼主用的是tomcat 6.0啦,按自己实际情况去修改
DSC0009.jpg

5.配置pom.xml
配置中有两点说明下:1、把jar包自动拷贝到web-inf目录地下,这个搞web开发都懂是为什么了;2、配置子项目依赖
<project xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/pom/4.0.0"
xmlns:xsi="http://www.w3.org/2001/xmlschema-instance">
<modelversion>4.0.0</modelversion>
<parent>
<artifactid>pdd-shop</artifactid>
<groupid>pdd-shop</groupid>
<version>0.0.1-snapshot</version>
</parent>
<groupid>pdd-shop</groupid>
<artifactid>pdd-shop-appweb</artifactid>
<version>0.0.1-snapshot</version>
<packaging>war</packaging>
<name>pdd-shop-appweb maven webapp</name>
<build>
<finalname>pdd-shop-appweb</finalname>
<plugins>
<plugin>
<artifactid>maven-antrun-plugin</artifactid>
<executions>
<execution>
<id>copy-lib-src-webapps</id>
<phase>package</phase>
<configuration>
<tasks>
<delete dir="webcontent/web-inf/lib" />
<copy todir="webcontent/web-inf/lib">
<fileset dir="target/${artifactid}/web-inf/lib">
<include name="*" />
</fileset>
</copy>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupid>${groupid}</groupid>
<artifactid>pdd-shop-application-impl</artifactid>
<version>${version}</version>
</dependency>
</dependencies>
</project>
项目依赖
DSC00010.jpg

扩展
DSC00011.jpg

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持CodeAE代码之家
原文链接:https://www.cnblogs.com/austinspark-jessylu/p/7053018.html

关注下面的标签,发现更多相似文章