手头上有个已上线的系统,但因老板的特殊要求,系统需要不断的修改。还有就是公司市场部不定期地在举行一些微信活动,每一个活动都是周期性的,活动完了这个功能就要在系统中移除。
系统中就有三种模块:已经在系统中正常运行不需要再变更的模块、经常性变更的模块、用完就要移除的活动模块。
简单说明一下:
eclipse版本:
Eclipse Java EE IDE for Web Developers.
Version: Luna Service Release 2 (4.4.2)
Build id: 20150219-0600
由于涉及到maven项目在eclipse上进行tomcat的集成调试,如果调试异常的朋友可以考虑更换版本比较高的eclipse版本。
maven版本: 2.2
maven相关的内容:http://blog.csdn.net/p_3er/article/category/2505419
maven多模块项目需要一个主项目来聚合各个子模块,不过其实就是需要一个父pom.xml。
这个pom.xml主要有两个内容:
<packaging>pompackaging>
<module>timetable-common</module>
<module>wechat-api</module>
<module>timetable-system</module>
<module>timetable-activity</module>
<module>timetable-main</module>
</modules>
完整的timetable/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/maven-v4_0_0.xsd">
<modelVersion>4.0.0modelVersion>
<groupId>com.benbengroupId>
<artifactId>timetableartifactId>
<packaging>pompackaging>
<version>2.0.0version>
<name>timetablename>
<url>http://maven.apache.orgurl>
<properties>
<project.version>2.0.0project.version>
<endorsed.dir>${project.build.directory}/endorsedendorsed.dir>
<project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
properties>
<modules>
<module>timetable-commonmodule>
<module>wechat-apimodule>
<module>timetable-activitymodule>
<module>timetable-mainmodule>
<module>timetable-systemmodule>
modules>
project>
通过eclipse,新建Maven Module.
新建一个模块名为timetable-common的simple project。
timetable-common/pom.xml:
<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.0modelVersion>
<parent>
<groupId>com.benbengroupId>
<artifactId>timetableartifactId>
<version>2.0.0version>
parent>
<artifactId>timetable-commonartifactId>
<name>timetable-commonname>
<url>http://maven.apache.orgurl>
<properties>
<project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
<javax.version>7.0javax.version>
<javax.servlet.version>3.1.0javax.servlet.version>
<javax.servlet.jstl.version>1.2javax.servlet.jstl.version>
<junit.version>4.12junit.version>
<log4j.version>1.2.16log4j.version>
<org.aspectj.version>1.7.3org.aspectj.version>
<net.sf.ehcache.version>2.3.2net.sf.ehcache.version>
<org.slf4j.version>1.6.1org.slf4j.version>
<mysql.jdbc.version>5.1.29mysql.jdbc.version>
<org.hibernate.entitymanager.version>3.6.3.Finalorg.hibernate.entitymanager.version>
<org.springframework.version>4.1.1.RELEASEorg.springframework.version>
<org.codehaus.jackson.version>1.7.4org.codehaus.jackson.version>
<net.sf.json-lib.version>2.4net.sf.json-lib.version>
<proxool.version>0.8.3proxool.version>
<javamail.version>1.4.1javamail.version>
<commons-codec.version>1.9commons-codec.version>
<commons-io.version>1.3.2commons-io.version>
<commons-fileupload.version>1.3.1commons-fileupload.version>
<xstream.version>1.4.3xstream.version>
<org.apache.jcs.version>1.3org.apache.jcs.version>
<joda-time.version>2.3joda-time.version>
<org.apache.poi.version>3.8org.apache.poi.version>
<com.fasterxml.jackson.core.version>2.3.3com.fasterxml.jackson.core.version>
<commons-httpclient.version>3.1commons-httpclient.version>
<jaxen.version>1.1.6jaxen.version>
<com.drewnoakes.version>2.8.1com.drewnoakes.version>
<com.google.zxing.version>3.0.0com.google.zxing.version>
<io.netty.version>5.0.0.Alpha2io.netty.version>
properties>
<dependencies>
<dependency>
<groupId>org.slf4jgroupId>
<artifactId>slf4j-jdk14artifactId>
<version>${org.slf4j.version}version>
dependency>
<dependency>
<groupId>javaxgroupId>
<artifactId>javaee-web-apiartifactId>
<version>${javax.version}version>
<scope>providedscope>
dependency>
<dependency>
<groupId>junitgroupId>
<artifactId>junitartifactId>
<version>${junit.version}version>
<scope>testscope>
dependency>
<dependency>
<groupId>org.hibernategroupId>
<artifactId>hibernate-entitymanagerartifactId>
<version>${org.hibernate.entitymanager.version}version>
dependency>
<dependency>
<groupId>net.sf.ehcachegroupId>
<artifactId>ehcache-coreartifactId>
<version>${net.sf.ehcache.version}version>
dependency>
<dependency>
<groupId>javax.servletgroupId>
<artifactId>jstlartifactId>
<version>${javax.servlet.jstl.version}version>
<scope>runtimescope>
dependency>
<dependency>
<groupId>javax.servletgroupId>
<artifactId>javax.servlet-apiartifactId>
<version>${javax.servlet.version}version>
dependency>
<dependency>
<groupId>log4jgroupId>
<artifactId>log4jartifactId>
<version>${log4j.version}version>
dependency>
<dependency>
<groupId>org.aspectjgroupId>
<artifactId>aspectjtoolsartifactId>
<version>${org.aspectj.version}version>
dependency>
<dependency>
<groupId>mysqlgroupId>
<artifactId>mysql-connector-javaartifactId>
<version>${mysql.jdbc.version}version>
dependency>
<dependency>
<groupId>proxoolgroupId>
<artifactId>proxoolartifactId>
<version>${proxool.version}version>
dependency>
<dependency>
<groupId>org.codehaus.jacksongroupId>
<artifactId>jackson-core-aslartifactId>
<version>${org.codehaus.jackson.version}version>
dependency>
<dependency>
<groupId>org.codehaus.jacksongroupId>
<artifactId>jackson-core-lgplartifactId>
<version>${org.codehaus.jackson.version}version>
dependency>
<dependency>
<groupId>org.codehaus.jacksongroupId>
<artifactId>jackson-mapper-aslartifactId>
<version>${org.codehaus.jackson.version}version>
dependency>
<dependency>
<groupId>org.codehaus.jacksongroupId>
<artifactId>jackson-mapper-lgplartifactId>
<version>${org.codehaus.jackson.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-aopartifactId>
<version>${org.springframework.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-context-supportartifactId>
<version>${org.springframework.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-beansartifactId>
<version>${org.springframework.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-contextartifactId>
<version>${org.springframework.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-coreartifactId>
<version>${org.springframework.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-expressionartifactId>
<version>${org.springframework.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-jdbcartifactId>
<version>${org.springframework.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-ormartifactId>
<version>${org.springframework.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-txartifactId>
<version>${org.springframework.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-webartifactId>
<version>${org.springframework.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-webmvcartifactId>
<version>${org.springframework.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-testartifactId>
<version>${org.springframework.version}version>
<scope>testscope>
dependency>
<dependency>
<groupId>com.fasterxml.jackson.coregroupId>
<artifactId>jackson-annotationsartifactId>
<version>${com.fasterxml.jackson.core.version}version>
dependency>
<dependency>
<groupId>com.fasterxml.jackson.coregroupId>
<artifactId>jackson-coreartifactId>
<version>${com.fasterxml.jackson.core.version}version>
dependency>
<dependency>
<groupId>com.fasterxml.jackson.coregroupId>
<artifactId>jackson-databindartifactId>
<version>${com.fasterxml.jackson.core.version}version>
dependency>
<dependency>
<groupId>joda-timegroupId>
<artifactId>joda-timeartifactId>
<version>${joda-time.version}version>
dependency>
<dependency>
<groupId>net.sf.json-libgroupId>
<artifactId>json-libartifactId>
<version>${net.sf.json-lib.version}version>
<classifier>jdk15classifier>
dependency>
<dependency>
<groupId>javax.mailgroupId>
<artifactId>mailartifactId>
<version>${javamail.version}version>
dependency>
<dependency>
<groupId>org.apache.jcsgroupId>
<artifactId>jcsartifactId>
<version>${org.apache.jcs.version}version>
dependency>
<dependency>
<groupId>commons-codecgroupId>
<artifactId>commons-codecartifactId>
<version>${commons-codec.version}version>
dependency>
<dependency>
<groupId>org.apache.commonsgroupId>
<artifactId>commons-ioartifactId>
<version>${commons-io.version}version>
dependency>
<dependency>
<groupId>commons-fileuploadgroupId>
<artifactId>commons-fileuploadartifactId>
<version>${commons-fileupload.version}version>
dependency>
<dependency>
<groupId>com.thoughtworks.xstreamgroupId>
<artifactId>xstreamartifactId>
<version>${xstream.version}version>
dependency>
<dependency>
<groupId>org.apache.httpcomponentsgroupId>
<artifactId>httpclientartifactId>
<version>4.5version>
dependency>
<dependency>
<groupId>org.apache.poigroupId>
<artifactId>poiartifactId>
<version>${org.apache.poi.version}version>
dependency>
<dependency>
<groupId>org.apache.poigroupId>
<artifactId>poi-ooxmlartifactId>
<version>${org.apache.poi.version}version>
dependency>
<dependency>
<groupId>commons-httpclientgroupId>
<artifactId>commons-httpclientartifactId>
<version>${commons-httpclient.version}version>
dependency>
<dependency>
<groupId>jaxengroupId>
<artifactId>jaxenartifactId>
<version>${jaxen.version}version>
dependency>
<dependency>
<groupId>com.drewnoakesgroupId>
<artifactId>metadata-extractorartifactId>
<version>${com.drewnoakes.version}version>
dependency>
<dependency>
<groupId>com.google.zxinggroupId>
<artifactId>coreartifactId>
<version>${com.google.zxing.version}version>
dependency>
<dependency>
<groupId>com.google.zxinggroupId>
<artifactId>javaseartifactId>
<version>${com.google.zxing.version}version>
dependency>
<dependency>
<groupId>io.nettygroupId>
<artifactId>netty-allartifactId>
<version>${io.netty.version}version>
dependency>
dependencies>
project>
配置比较简单:
<parent>
<groupId>com.benbengroupId>
<artifactId>timetableartifactId>
<version>2.0.0version>
parent>
<artifactId>timetable-commonartifactId>
<name>timetable-commonname>
<url>http://maven.apache.orgurl>
<packaging>jarpackaging>
使用a中相同的方法新建wechat-api模块。
wechat-api/pom.xml:
<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.0modelVersion>
<parent>
<groupId>com.benbengroupId>
<artifactId>timetableartifactId>
<version>2.0.0version>
parent>
<artifactId>wechat-apiartifactId>
<name>wechat-apiname>
<url>http://maven.apache.orgurl>
<properties>
<project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
properties>
<dependencies>
<dependency>
<groupId>com.benbengroupId>
<artifactId>timetable-commonartifactId>
<version>${project.version}version>
dependency>
dependencies>
project>
<dependencies>
<dependency>
<groupId>com.benbengroupId>
<artifactId>timetable-commonartifactId>
<version>${project.version}version>
dependency>
dependencies>
timetable-system模块的新建与模块与wechat-api模块的方式与配置雷同。只是timetable-system模块依赖的是wechat-api模块。当然,通过依赖wechat-api,同时也依赖了timetable-common。
与使用eclipse创建一个独立的maven web project一样,创建一个maven web module。
注意:我们不是创建简单的模块
通过Filter过滤后,选择maven-archetype-webapp。
创建完成后的模块类似一个的java web项目:
在此模块下,我们和正常的java web开发一下,在src/main/java下写java代码,src/main/resources下放配置文件,src/main/webapp下写web相关的代码及资源。
timetable-activity/pom.xml:
<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.0modelVersion>
<parent>
<groupId>com.benbengroupId>
<artifactId>timetableartifactId>
<version>2.0.0version>
parent>
<artifactId>timetable-activityartifactId>
<packaging>warpackaging>
<name>timetable-activity Maven Webappname>
<url>http://maven.apache.orgurl>
<dependencies>
<dependency>
<groupId>com.benbengroupId>
<artifactId>timetable-systemartifactId>
<version>${project.version}version>
dependency>
dependencies>
<build>
<finalName>timetable-activityfinalName>
<plugins>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-war-pluginartifactId>
<configuration>
<failOnMissingWebXml>falsefailOnMissingWebXml>
configuration>
plugin>
plugins>
build>
project>
<dependency>
<groupId>com.benbengroupId>
<artifactId>timetable-systemartifactId>
<version>${project.version}version>
dependency>
<packaging>warpackaging>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-war-pluginartifactId>
<configuration>
<failOnMissingWebXml>falsefailOnMissingWebXml>
configuration>
plugin>
像3.4那样创建一个timetable-main的maven web module。
timetable-main/pom.xml:
<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.0modelVersion>
<parent>
<groupId>com.benbengroupId>
<artifactId>timetableartifactId>
<version>2.0.0version>
parent>
<artifactId>timetable-mainartifactId>
<packaging>warpackaging>
<name>timetable-mainname>
<url>http://maven.apache.orgurl>
<dependencies>
<dependency>
<groupId>com.benbengroupId>
<artifactId>timetable-systemartifactId>
<version>${project.version}version>
dependency>
<dependency>
<groupId>com.benbengroupId>
<artifactId>timetable-activityartifactId>
<version>${project.version}version>
<type>wartype>
dependency>
dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-war-pluginartifactId>
<configuration>
<packagingExcludes>WEB-INF/web.xmlpackagingExcludes>
<overlays>
<overlay>
<groupId>com.benbengroupId>
<artifactId>timetable-activityartifactId>
overlay>
overlays>
configuration>
plugin>
plugins>
build>
project>
<dependency>
<groupId>com.benbengroupId>
<artifactId>timetable-activityartifactId>
<version>${project.version}version>
<type>wartype>
dependency>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-war-pluginartifactId>
<configuration>
<packagingExcludes>WEB-INF/web.xmlpackagingExcludes>
<overlays>
<overlay>
<groupId>com.benbengroupId>
<artifactId>timetable-activityartifactId>
overlay>
overlays>
configuration>
plugin>
多web项目在eclipse+tomcat环境下部署调试和单个maven web项目的方式是一样的:
再去tomcat目录,发现已经将合并后的web发布到对应目录下了。 依赖的打包方式为jar的maven module已经被打包成jar发布到lib下了,而依赖的打包方式为war则和之前一样,编译文件会发布到classes下。不过你可以打个断点试试,依然可以调试,修改一段代码,发现热部署也是可以的,这样就和原来的开发习惯完全一样了。
注意: