使用maven进行分模块/工程进行开发,需要注意的地方

1、在使用maven进行多模块、多工程开发时,在父project的pom.xml文件中,需要将<packaging>标签修改为<packaging>pom</packaging>
主web模块打成war包,其他web子模块也需要打成war包,其他如entity、service、dao等子模块要打成jar包。
2、主web模块的pom.xml文件,需要在<build>标签中增加,以下包含2个子模块的依赖,分别是<artifactId>customerweb</artifactId><artifactId>goodsweb</artifactId>

<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
				<version>2.4</version>
				<configuration>
					<overlays>
						<overlay>
							<groupId>com.myproject</groupId>
							<artifactId>customerweb</artifactId>
						</overlay>
						<overlay>
							<groupId>com.myproject</groupId>
							<artifactId>goodsweb</artifactId>
						</overlay>
					</overlays>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.mortbay.jetty</groupId>
				<artifactId>jetty-maven-plugin</artifactId>
				<version>8.1.16.v20140903</version>
				<configuration>
					<scanIntervalSeconds>10</scanIntervalSeconds>
					<stopPort>9999</stopPort>
					<webAppConfig>
						<contextPath>/</contextPath>
					</webAppConfig>
					<connectors>
						<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
							<port>9080</port>
							<maxIdleTime>60000</maxIdleTime>
						</connector>
					</connectors>
				</configuration>
			</plugin>
		</plugins>

增加jetty-maven-plugin这个plugin是为了该web模块可以使用jetty运行测试。
依赖关系也需要增加,在标签<dependencies>下增加依赖的模块,注意依赖的web模块,一定要设置type标签为<type>war</type>,例如:

	<dependencies>
		<dependency>
			<groupId>com.myproject</groupId>
			<artifactId>customerweb</artifactId>
			<version>0.0.1-SNAPSHOT</version>
			<type>war</type>
		</dependency>
		<dependency>
			<groupId>com.myproject</groupId>
			<artifactId>goodsweb</artifactId>
			<version>0.0.1-SNAPSHOT</version>
			<type>war</type>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>
	</dependencies>

3、如果某个模块依赖其他子模块,需要在这个模块的pom.xml文件中增加依赖关系,在<dependencies>标签里增加,例如:

<dependency>
	<groupId>com.myproject</groupId>
	<artifactId>customer</artifactId>
	<version>0.0.1-SNAPSHOT</version>
</dependency>

4、如果某个web子模块要单独运行测试,pom.xml也需要增加plugin,在标签<build>下增加,这样可以使用jetty运行,进行测试:

			<plugin>
				<groupId>org.mortbay.jetty</groupId>
				<artifactId>jetty-maven-plugin</artifactId>
				<version>8.1.16.v20140903</version>
				<configuration>
					<scanIntervalSeconds>10</scanIntervalSeconds>
					<stopPort>9999</stopPort>
					<webAppConfig>
						<contextPath>/</contextPath>
					</webAppConfig>
					<connectors>
						<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
							<port>9080</port>
							<maxIdleTime>60000</maxIdleTime>
						</connector>
					</connectors>
				</configuration>
			</plugin>

5、项目中各个子模块依赖的公共的jar包等,可以配置在父工程的pom.xml中,这样其他子模块就可以不用配置了。
6、在eclipse中运行某个子模块,可以如下配置:
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值