如何使用eclipse搭建maven多module项目(构建父子项目)
程序员文章站
2024-03-04 12:34:53
创建空maven项目
1、file–>new–>project…
2.next
3.next
4.finish
5.配置pom.xml...
创建空maven项目
1、file–>new–>project…
2.next
3.next
4.finish
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…
2.next
3.next
4.next
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
3.把包名定义下~
4.右键pdd-shop-appweb项目–>properties–>project facets–>convert to faceted form..
这里选2.4版本的web工程是因为楼主用的是tomcat 6.0啦,按自己实际情况去修改
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>
项目依赖
扩展
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
上一篇: Python字符串拼接的几种方法整理
下一篇: L的java学习笔记——数组