Maven命令行来创建项目 http://everlook.iteye.com/blog/1446672
Maven最佳实践:划分模块 http://blog.csdn.net/yydcj/article/details/8698222
如果碰到问题,或者觉得不详细,可以参考
http://blog.csdn.net/yydcj/article/details/8699633
一些命令说明:
直接创建maven web项目
mvn archetype:create -DgroupId=cn.everlook.myweb -DartifactId=myweb -DarchetypeArtifactId=maven-archetype-webapp
说明:archetypeArtifactId(项目骨架的类型)
* maven-archetype-archetype
* maven-archetype-j2ee-simple
* maven-archetype-mojo
* maven-archetype-portlet
* maven-archetype-profiles (currently under development)
* maven-archetype-quickstart
* maven-archetype-simple (currently under development)
* maven-archetype-site
* maven-archetype-site-simple
* maven-archetype-webapp
然后进入myweb目录,执行mvn eclipse:eclipse -Dwtpversion=2.0,这就可以用wtp插件发布了。
根据原文,我得到自己的操作:
环境: Maven 3.0.x, OS: Fedora17
1.创建父工程,并配置
mvn archetype:create -DgroupId=com.pandy.p -DartifactId=PandyTest -DarchetypeArtifactId=maven-archetype-quickstart
cd PandyTest
rm -rf src
修改pom.xml里面的packaging为pom;
设定父工程的编译等级:
Maven最佳实践:划分模块 http://blog.csdn.net/yydcj/article/details/8698222
如果碰到问题,或者觉得不详细,可以参考
http://blog.csdn.net/yydcj/article/details/8699633
一些命令说明:
直接创建maven web项目
mvn archetype:create -DgroupId=cn.everlook.myweb -DartifactId=myweb -DarchetypeArtifactId=maven-archetype-webapp
说明:archetypeArtifactId(项目骨架的类型)
* maven-archetype-archetype
* maven-archetype-j2ee-simple
* maven-archetype-mojo
* maven-archetype-portlet
* maven-archetype-profiles (currently under development)
* maven-archetype-quickstart
* maven-archetype-simple (currently under development)
* maven-archetype-site
* maven-archetype-site-simple
* maven-archetype-webapp
然后进入myweb目录,执行mvn eclipse:eclipse -Dwtpversion=2.0,这就可以用wtp插件发布了。
根据原文,我得到自己的操作:
环境: Maven 3.0.x, OS: Fedora17
1.创建父工程,并配置
mvn archetype:create -DgroupId=com.pandy.p -DartifactId=PandyTest -DarchetypeArtifactId=maven-archetype-quickstart
cd PandyTest
rm -rf src
修改pom.xml里面的packaging为pom;
设定父工程的编译等级:
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.7</source>
- <target>1.7</target>
- <encoding>UTF-8</encoding>
- </configuration>
- </plugin>
- </plugins>
- </build>
<build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.7</source> <target>1.7</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> </build>
2.创建子工程,并做相应配置
mvn archetype:create -DgroupId=com.pandy.p -DartifactId=PandyC1 -DarchetypeArtifactId=maven-archetype-quickstart
mvn archetype:create -DgroupId=com.pandy.p -DartifactId=PandyC2 -DarchetypeArtifactId=maven-archetype-webapp
Web模块设定对C1工程的依赖:
- <dependency>
- <groupId>com.pandy.p</groupId>
- <artifactId>PandyC1</artifactId>
- <version>1.0-SNAPSHOT</version>
- </dependency>
<dependency> <groupId>com.pandy.p</groupId> <artifactId>PandyC1</artifactId> <version>1.0-SNAPSHOT</version> </dependency>
Web模块设定插件,eclipse插件,jetty插件,注意<finalName>PandyC2</finalName>和
- <contextPath>/PandyC2</contextPath>节点:
- <build>
- <finalName>PandyC2</finalName>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-eclipse-plugin</artifactId>
- <configuration>
- <wtpmanifest>true</wtpmanifest>
- <wtpapplicationxml>true</wtpapplicationxml>
- <wtpversion>2.0</wtpversion>
- </configuration>
- </plugin>
- <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>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.5</version>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-war-plugin</artifactId>
- <version>2.1.1</version>
- <configuration>
- <archive>
- <manifest>
- <!--<addClasspath>true</addClasspath> -->
- </manifest>
- <manifestEntries>
- <Built-By>org-builder</Built-By>
- <Build-Jdk>${java.version}</Build-Jdk>
- </manifestEntries>
- </archive>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.mortbay.jetty</groupId>
- <artifactId>maven-jetty-plugin</artifactId>
- <version>6.1.20</version>
- <configuration>
- <contextPath>/PandyC2</contextPath>
- <!--<webDefaultXml>webdefault.xml</webDefaultXml> -->
- <scanIntervalSeconds>0</scanIntervalSeconds>
- <scanTargetPatterns>
- <scanTargetPattern>
- <directory>src/main/webapp/WEB-INF</directory>
- <excludes>
- <exclude>**/*.jsp</exclude>
- </excludes>
- <includes>
- <include>**/*.properties</include>
- <include>**/*.xml</include>
- </includes>
- </scanTargetPattern>
- </scanTargetPatterns>
- </configuration>
- </plugin>
- <plugin>
- <artifactId>maven-war-plugin</artifactId>
- <version>2.0.2</version>
- <configuration>
- <archive>
- <manifest>
- <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
- </manifest>
- <manifestEntries>
- <Implementation-Build>${buildNumber}</Implementation-Build>
- </manifestEntries>
- </archive>
- <dependentWarExcludes>
- **/jdbc.properties,**/web.xml,WEB-INF/classes/META-INF/**
- </dependentWarExcludes>
- </configuration>
- </plugin>
- </plugins>
- </build>
<contextPath>/PandyC2</contextPath>节点: <build> <finalName>PandyC2</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-eclipse-plugin</artifactId> <configuration> <wtpmanifest>true</wtpmanifest> <wtpapplicationxml>true</wtpapplicationxml> <wtpversion>2.0</wtpversion> </configuration> </plugin> <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> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.5</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.1.1</version> <configuration> <archive> <manifest> <!--<addClasspath>true</addClasspath> --> </manifest> <manifestEntries> <Built-By>org-builder</Built-By> <Build-Jdk>${java.version}</Build-Jdk> </manifestEntries> </archive> </configuration> </plugin> <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId> <version>6.1.20</version> <configuration> <contextPath>/PandyC2</contextPath> <!--<webDefaultXml>webdefault.xml</webDefaultXml> --> <scanIntervalSeconds>0</scanIntervalSeconds> <scanTargetPatterns> <scanTargetPattern> <directory>src/main/webapp/WEB-INF</directory> <excludes> <exclude>**/*.jsp</exclude> </excludes> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> </scanTargetPattern> </scanTargetPatterns> </configuration> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <version>2.0.2</version> <configuration> <archive> <manifest> <addDefaultImplementationEntries>true</addDefaultImplementationEntries> </manifest> <manifestEntries> <Implementation-Build>${buildNumber}</Implementation-Build> </manifestEntries> </archive> <dependentWarExcludes> **/jdbc.properties,**/web.xml,WEB-INF/classes/META-INF/** </dependentWarExcludes> </configuration> </plugin> </plugins> </build>
3.针对eclipse处理
退回到父目录:mvn eclipse:eclipse , 或者: mvn eclipse:eclipse -Dwtpversion=2.0
别人的命令:mvn eclipse:eclipse -Dwtpversion=1.0
记得不要缺少 -Dwtpversion=1.0,这个说明了eclipse认出它就是web项目,而不是简单的java项目,大家应该知道web项目在eclipse可以做一些其他的事情吧。
修改Webapp工程的.classpath文件,增加:这个很重要
<classpathentry kind="src" path="src/main/java" including="**/*.java"/>
否则,导入之后,创建java的代码,总是在eclipse上位置现实不对。
倒入到eclipse, 导入的时候选择Maven已存在项目,选择父工程的根目录。
会看见导入三个工程,其中子工程有错误,点击错误右键,快速修复(Quick Fix),即可解决问题
如果要在eclipse中使用m2eclipse,需要使用:
mvn eclipse:m2eclipse
4. 编译过程:
到父工程右键--运行方式--Maven clean , Maven install。
这个过程
A: 自动会编译子模块C1,并打包成jar,
B: 自动会编译子模块C2,并打包成war, 并把C1生成的jar放到C2.war下面去。
5. eclipse运行webapp工程:
因为C2是Webapp的工程,所以必须跑到C2下面执行: jetty:run
问题:如何实时调试C1的java代码?
Maven多模块项目 eclipse热部署 Maven项目实现 tomcat热部署 http://blog.csdn.net/laoshuisheng/article/details/6420003
多模块Maven环境下,如何在eclipse构建J2EE调试环境(热替换)http://www.cnblogs.com/hsiayong/archive/2012/06/25/2561185.html
关于部署,可以参考:http://panyongzheng.iteye.com/blog/1866757
其他:
按照上面的带的三个pom.xml大概如下:
父pom.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <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>com.pandy.p</groupId>
- <artifactId>PandyTest</artifactId>
- <version>1.0-SNAPSHOT</version>
- <packaging>pom</packaging>
- <name>PandyTest</name>
- <url>http://maven.apache.org</url>
- ..........
- <modules>
- <module>PandyC1</module>
- <module>PandyC2</module>
- </modules>
- </project>
<?xml version="1.0" encoding="UTF-8"?> <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>com.pandy.p</groupId> <artifactId>PandyTest</artifactId> <version>1.0-SNAPSHOT</version> <packaging>pom</packaging> <name>PandyTest</name> <url>http://maven.apache.org</url> .......... <modules> <module>PandyC1</module> <module>PandyC2</module> </modules> </project>
非Webapp的子Module pom.xml
- <?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>
- <groupId>com.pandy.p</groupId>
- <artifactId>PandyTest</artifactId>
- <version>1.0-SNAPSHOT</version>
- </parent>
- <groupId>com.pandy.p</groupId>
- <artifactId>PandyC1</artifactId>
- <version>1.0-SNAPSHOT</version>
- <name>PandyC1</name>
- <url>http://maven.apache.org</url>
- .....
- .....
- </project>
<?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> <groupId>com.pandy.p</groupId> <artifactId>PandyTest</artifactId> <version>1.0-SNAPSHOT</version> </parent> <groupId>com.pandy.p</groupId> <artifactId>PandyC1</artifactId> <version>1.0-SNAPSHOT</version> <name>PandyC1</name> <url>http://maven.apache.org</url> ..... ..... </project>
Webapp的子Module pom.xml
- <?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>
- <groupId>com.pandy.p</groupId>
- <artifactId>PandyTest</artifactId>
- <version>1.0-SNAPSHOT</version>
- </parent>
- <groupId>com.pandy.p</groupId>
- <artifactId>PandyC2</artifactId>
- <version>1.0-SNAPSHOT</version>
- <packaging>war</packaging>
- <name>PandyC2 Maven Webapp</name>
- <url>http://maven.apache.org</url>
- <dependencies>
- ......
- <dependency>
- <groupId>com.pandy.p</groupId>
- <artifactId>PandyC1</artifactId>
- <version>1.0-SNAPSHOT</version>
- </dependency>
- </dependencies>
- <build>
- <finalName>PandyC2</finalName>
- ......
- </build>
- </project>
<?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> <groupId>com.pandy.p</groupId> <artifactId>PandyTest</artifactId> <version>1.0-SNAPSHOT</version> </parent> <groupId>com.pandy.p</groupId> <artifactId>PandyC2</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <name>PandyC2 Maven Webapp</name> <url>http://maven.apache.org</url> <dependencies> ...... <dependency> <groupId>com.pandy.p</groupId> <artifactId>PandyC1</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies> <build> <finalName>PandyC2</finalName> ...... </build> </project>
其实,两个子Module的pom.xml可以去掉
<groupId>com.pandy.p</groupId>,<version>1.0-SNAPSHOT</version>
因为他们自己的pom.xml里面的parent节点,已经定义了。
相关推荐
eclipse创建多模块项目
NULL 博文链接:https://zlrzlm7454.iteye.com/blog/2321724
这个工程代码,是在ECLIPSE下面建立的,应用Gradle作为构建工具,建立的一个多模块项目。注意不是Maven下的多模块项目。
eclipse下创建ssm+MySQL+maven多模块项目。此demo用于提供给新手学习使用,如有不妥之处请联系楼主
maven多模块项目,使用eclipse开发工具创建,有意可下载,没有解压密码
构建这个多模块项目 6.6. 运行Web应用 7. 多模块企业级项目 7.1. 简介 7.1.1. 下载本章样例 7.1.2. 多模块企业级项目 7.1.3. 本例中所用的技术 7.2. simple-parent项目 7.3. simple-model模块 7.4. ...
java班级管理源码Maven 初学者教程 - 28 分钟内的示例 安装 Eclipse 和 Java 课程大纲 我们将使用 ...Maven ...Maven ...Maven ...多模块 Maven 项目。 第 8 步:我们将学习如何创建战争,部署到 tomcat。 运
一、前言最近公司项目准备开始重构,框架选定为 Spring Boot ,本篇主要记录了在 IDEA 中搭建 Spring Boot Maven 多模块项目的过程。二、软件及硬件环境macOS Sierra 10.12.6IntelliJ IDEA 2018.2JDK 1.8Maven 3.2.1...
第6课 使用Maven构建多模块项目(一) 第7课 使用Maven构建多模块项目(二) 第8课 使用Nexus搭建Maven私服 第9课 使用Maven管理新闻系统开发-项目简介 第10课 使用Maven管理新闻系统开发-项目搭建(一) 第11课 ...
项目介绍: 本系统功能包括: 一: 商品模块:商品添加、规格设置,商品上下架等 ...2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行
②使用【Maven】创建项目 目前不知道使用Eclipse导入该项目,是否可以直接预加载,没有测试过,谨慎谨慎再谨慎!(Eclipse的兼容性较低,建议可以直接尝试做新项目时更换)。如果购买者是因为所学内容有限,还不知道...
Foweb框架一个基于Spring + SpringMVC + Mybatis的多模块Maven项目。一个基于Spring + SpringMVC + Mybatis的Maven多模块项目。使用文档两种使用方式:1.直接将项目下载下来,然后在IDE(Eclipse或IDEA)中以maven...
tycho-eclipse-plugin-原型这个原型将创建一个具有嵌套结构的多模块项目: __artifactId__ : parent pom project | |---__artifactId__.core : eclipse-plugin | |---__artifactId__.feature: eclipse-feature | |--...
在动手创建一个多模块maven Java Web应用程序项目的同时,掌握Maven的核心概念。 - Convention over configuration and the Maven project structure - Maven life cycle phases and goals - The Project Object ...
由Maven生成Eclipse工程文件 9 导入模块进Eclipse 9 在Eclipse中运行GeoServer 12 访问GeoServer首页 13 Maven指南 13 安装Maven 13 运行Maven 13 构建 13 跳过测试 14 离线构建 14 构建扩展 14 Profiles 15 Eclipse...
Maven包:Maven3.3.9 三、系统划分与功能 该系统分为前台展示和后台管理两大模块。 前台功能:用户登录、用户注册 首页,轮播图特效、个人中心、我的订单、我的收藏、加入购物车、购物车结算、支付(包括支付宝,...
开发环境jdk+maven项目,使用Tomcat7开发 1. 将系统的源码放到电脑的某个盘下面。 2. 打开Eclipse,点击File选中General--->选择Existing Projects into Workspace--->选择Select archive file。 3. 选择要导入的项目...