Web开发学习(1)使用eclipse搭建maven项目

首先用eclipse创建工程 new -> project -> maven -> maven project
点击next 进入Select an Archetype 界面,选择maven archetype webapp
点击next进入Specify Archetype parameters界面,给工程指定 groupId和artifactId点击finish完成工程搭建
maven项目将通过pom.xml文件控制,为方便起见会将一个罗列了很多包和插件及服务器地址配置的pom工程作为我们当前pom的父类,是要父类在中央仓中,我们只需在自己工程的pom中对其引用即可
<parent>
	<groupId>net.project</groupId>
	<artifactId>project-parent</artifactId>
	<version>2.0.0</version>
</parent>

接下去我就可以使用父pom罗列的包和插件了,比如我在父pom中罗列了一个jetty插件
<build>
		<pluginManagement>
			<plugins>
<!-- jetty插件 -->
				<plugin>
					<groupId>org.mortbay.jetty</groupId>
					<artifactId>maven-jetty-plugin</artifactId>
					<version>${jetty.version}</version>
					<!-- <configuration> <reload>manual</reload> </configuration> -->
					<configuration>
						<webDefaultXml>src/main/resources/webdefault.xml</webDefaultXml>
						<scanIntervalSeconds>0</scanIntervalSeconds>
						<contextPath>/test</contextPath>
						<connectors>
							<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
								<port>8080</port>
								<maxIdleTime>60000</maxIdleTime>
							</connector>
						</connectors>
						<stopPort>9966</stopPort>
						<stopKey>jetty</stopKey>
					</configuration>
				</plugin>
</plugins>
		</pluginManagement>
	</build>


那我们的工程将拥有jetty插件的功能,但是大多数情况下多个子工程继承一个父pom所以需要对插件信息进行重写,如contextPath,porty等,默认是父类的参数;但是jar和插件不一样,父类罗列jar文件只是一个展示,继承它的工程是没有引用这些jar的需要在自己的pom中声明引用(一般父类罗列的jar包含了所有子工程需要的jar包,所以这样也是有一定的道理)
<dependency>
	<groupId>org.springframework</groupId>
	<artifactId>spring-webmvc</artifactId>
</dependency>

为什么引入包不需要指定版本呢? 对的,在父pom罗列中已经有指定了,默认为父pom的版本

个人之前没用过ant,不能进行对比,但是试用maven的方式管理项目的确是非常值得使用的


猜你喜欢

转载自sdh88hf.iteye.com/blog/1202846
今日推荐