Maven学习日记(二)---MAVEN创建多模块的项目
手动构建多模块maven项目,这个simple-parent项目下有两个子模块,一个是jar包型的simple-weather和一个war型的simple-webapp
1.创建一个父的simple-parent项目
D:\>mvn archetype:create -DgroupId=org.sonatype.mavenbook.ch06 -DartifactId=simp
le-parent -DpackageName=org.sonatype.mavenbook -DarchetypeArtifactId=maven-arche
type-webapp
2.修改里面的pom文件如下
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.sonatype.mavenbook.ch06</groupId>
<artifactId>simple-parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>simple-parent Maven Webapp</name>
<url>http://maven.apache.org</url>
<modules>
<module>simple-weather</module>
<module>simple-webapp</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
3.在simple-parent下创建maven子项目是会出错.如下
D:\simple-parent>mvn archetype:create -DgroupId=org.sonatype.mavenbook.weather -
DartifactId=simple-weather
org.apache.maven.reactor.MavenExecutionException: Could not find the model file
'D:\simple-parent\simple-weather\pom.xml'. for project unknown
at org.apache.maven.DefaultMaven.getProjects(DefaultMaven.java:376)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:289)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:126)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:282)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
将这个pom移到别的地方就能正常运行(simple-parent目录下的pom.xml)
4.修改simple-weather中的pom文件
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.sonatype.mavenbook.ch06</groupId>
<artifactId>simple-parent</artifactId>
<version>1.0</version>
</parent>
<artifactId>simple-weather</artifactId>
<packaging>jar</packaging>
<name>Chapter 6 Simple Weather API</name>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
其它包中的内容直接copy过来
5.创建simple-webapp
D:\simple-parent>mvn archetype:create -DgroupId=org.sonatype.mavenbook.web -Dart
ifactId=simple-webapp -DpackageName=org.sonatype.mavenbook -DarchetypeArtifactId
=maven-archetype-webapp
6.修改simple-webapp中的pom文件
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.sonatype.mavenbook.ch06</groupId>
<artifactId>simple-parent</artifactId>
<version>1.0</version>
</parent>
<artifactId>simple-webapp</artifactId>
<packaging>war</packaging>
<name>simple-webapp Maven Webapp</name>
<dependencies>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_2.4_spec</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.sonatype.mavenbook.ch06</groupId>
<artifactId>simple-weather</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<build>
<finalName>simple-webapp</finalName>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
7.从sample中copy包源码与web.xml
8.进入simple-parent中构建多模块项目mvn clean install
9.运行mvn jetty:run
10.可以构建为eclipse项目mvn eclipse:eclipse
11.访问http://localhost:8080/simple-webapp/weather?zip=110
相关资料:
参与书籍:maven权威指南
链接:http://www.sonatype.com/books/maven-book/reference_zh/public-book.html
书中源码下载地址:http://www.sonatype.com/book/mvn-examples-1.0.zip
最新文章
- [转]windows下和Ubuntu下adb找不到设备的解决方法
- MMORPG大型游戏设计与开发(客户端架构 part3 of vegine)
- 修改开机启动等待时间(for Ubuntu12.10)
- 解决ultravnc在win2008 R2下CTRL+ALT+DELETEA组合键发送失败的问题
- Spring 注解 @Resource和@Autowired(转)
- cf Strings of Power
- shell之rm -rf的别名设置
- 利用PhantomJS进行网页截屏
- tensorflow Relu激活函数
- Java基础总结--多线程总结2
- thinkphp5基础
- Android进阶(二十八)上下文菜单ContextMenu使用案例
- 一段奇葩Javascript代码引发的思考
- Perl IO:IO重定向
- redis 在 php 中的应用
- webpack的externals的使用
- 经典算法问题的java实现 (一)
- wkhtmltopdf 安装过程不包含php扩展部分
- 【BZOJ1089】[SCOI2003]严格n元树(高精度,动态规划)
- 浅谈js设计模式之迭代器模式
热门文章
- BEGINNING SHAREPOINT&;#174; 2013 DEVELOPMENT 第13章节--使用业务连接服务创建业务线解决方式 SP Apps中的BCS
- go系列之数组
- 跟我一起学习VIM - vim插件合集
- [na]锐起无盘机并发部署多台windows
- 翻翻git之---效果鲜明的类ViewPager库 ConvenientBanner(对图片载入部分进行改动)
- ORACLE 11G在存储过程里面遍历游标, 调用job任务定时运行
- Cocos-2d 坐标系
- poi 抽取execl表面数据源代码工具
- Django 缓存、信号
- JAVA-JSP动作元素之forward