maven+springMvc+velocity
在主项目目录下面比如:ZZ91文件夹下面 使用mvn命令创建一个web项目,common service persist三个java项目.
common用来存放domain实体类
service层用来存放service 和serviceImpl业务逻辑的实现
persist曾用来存放dao层持久层,和对应实体类的xml映射文件.
然后在该文件夹下面编写父类的pom文件
<?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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.ast1949</groupId> <artifactId>ast1949-parent</artifactId> <name>ast1949-parent</name> <packaging>pom</packaging> <version>1.0.0-SNAPSHOT</version> <properties> <java.source.version>1.6</java.source.version> <java.target.version>1.6</java.target.version> <encoding>UTF-8</encoding> <project.version>1.0.0-SNAPSHOT</project.version> <project.prefix>ast</project.prefix> <!--Linux环境--> <package.environment>dev</package.environment> <jdbc.location>classpath:persist.properties</jdbc.location> </properties> <developers> <developer> <id>mays</id> <name>mays</name> <email>lvjavapro@163.com</email> </developer> </developers> <modules> <module>ast1949-common</module> <module>ast1949-service</module> <module>ast1949-persist</module> <module>ast1949-photos</module> </modules>
//下面是依赖包 <dependencyManagement> <dependencies> <dependency> <groupId>com.zz91</groupId> <artifactId>zz91-utils</artifactId> <version>2.0.1</version> </dependency> <dependency> <groupId>com.zz91</groupId> <artifactId>zz91-search-utils-old</artifactId> <version>1.0.0</version> </dependency> <dependency> <groupId>simplecaptcha</groupId> <artifactId>simplecaptcha</artifactId> <version>1.2.1</version> </dependency> <dependency> <groupId>patchca</groupId> <artifactId>patchca</artifactId> <version>0.5.0</version> </dependency> <dependency> <groupId>commons-httpclient</groupId> <artifactId>commons-httpclient</artifactId> <version>3.1</version> </dependency> <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>com.ast1949</groupId> <artifactId>ast1949-common</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> <dependency> <groupId>com.ast1949</groupId> <artifactId>ast1949-service</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> <dependency> <groupId>com.ast1949</groupId> <artifactId>ast1949-persist</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> <dependency> <groupId>com.zz91</groupId> <artifactId>zz91-mail-client</artifactId> <version>1.1.3-beta</version> </dependency> <dependency> <groupId>com.zz91</groupId> <artifactId>zz91-searchengine</artifactId> <version>1.0.1-SNAPSHOT</version> </dependency> <!-- <dependency> <groupId>com.zz91</groupId> <artifactId>zz91-import</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> --> <dependency> <groupId>com.zz91</groupId> <artifactId>zz91-stat</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.0</version> <scope>test</scope> </dependency> <dependency> <groupId>cactus</groupId> <artifactId>cactus-maven</artifactId> <version>1.7</version> <scope>test</scope> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.14</version> </dependency> <dependency> <groupId>com.sleepycat</groupId> <artifactId>je</artifactId> <version>3.3.82</version> </dependency> <dependency> <groupId>c3p0</groupId> <artifactId>c3p0</artifactId> <version>0.9.1.2</version> </dependency> <dependency> <groupId>org.apache.ibatis</groupId> <artifactId>ibatis-sqlmap</artifactId> <version>2.3.4.726</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.6</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>2.5.6</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> <version>2.5.6</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>2.5.6</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>2.5.6</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>2.5.6</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>2.5.6</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>2.5.6</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>2.5.6</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>2.5.6</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.6.4</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.6.4</version> </dependency> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity</artifactId> <version>1.6.1</version> </dependency> <dependency> <groupId>velocity-tools</groupId> <artifactId>velocity-tools</artifactId> <version>1.4</version> </dependency> <dependency> <groupId>net.sf.json-lib</groupId> <artifactId>json-lib</artifactId> <version>2.2.3</version> <classifier>jdk15</classifier> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> <scope>provided</scope> </dependency> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.4</version> </dependency> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.2.1</version> </dependency> <dependency> <groupId>commons-digester</groupId> <artifactId>commons-digester</artifactId> <version>1.8</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>1.4</version> </dependency> <dependency> <groupId>javax.mail</groupId> <artifactId>mail</artifactId> <version>1.4</version> </dependency> <dependency> <groupId>quartz</groupId> <artifactId>quartz</artifactId> <version>1.5.2</version> </dependency> <dependency> <groupId>org.apache.lucene</groupId> <artifactId>lucene-core</artifactId> <version>3.3.0</version> </dependency> <dependency> <groupId>org.apache.lucene</groupId> <artifactId>lucene-demos</artifactId> <version>3.3.0</version> </dependency> <dependency> <groupId>org.apache.lucene</groupId> <artifactId>lucene-highlighter</artifactId> <version>3.3.0</version> </dependency> <dependency> <groupId>org.wltea.analyzer.lucene</groupId> <artifactId>IKAnalyzer</artifactId> <version>3.2.0</version> </dependency> <dependency> <groupId>net.spy</groupId> <artifactId>memcached</artifactId> <version>2.5rc1</version> </dependency> <dependency> <groupId>jexcelapi</groupId> <artifactId>jxl</artifactId> <version>2.6</version> </dependency> <dependency> <groupId>manentia</groupId> <artifactId>manentia-commons</artifactId> <version>2.0.4</version> </dependency> <dependency> <groupId>org.directwebremoting</groupId> <artifactId>dwr</artifactId> <version>2.0.1</version> </dependency> <dependency> <groupId>xerces</groupId> <artifactId>xercesImpl</artifactId> <version>2.9.1</version> </dependency> <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <version>1.2.2</version> </dependency> <dependency> <groupId>org.jasypt</groupId> <artifactId>jasypt</artifactId> <version>1.5</version> </dependency> <dependency> <groupId>org.tuckey</groupId> <artifactId>urlrewritefilter</artifactId> <version>3.1.0</version> </dependency> <dependency> <!-- jsoup HTML parser library @ http://jsoup.org/ --> <groupId>org.jsoup</groupId> <artifactId>jsoup</artifactId> <version>1.3.3</version> </dependency> <!-- rpc begin <dependency> <groupId>com.usharp</groupId> <artifactId>usharp-common</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> <dependency> <groupId>com.usharp</groupId> <artifactId>usharp-rpc</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> --> <!--rpc end--> <dependency> <groupId>org.apache.mina</groupId> <artifactId>mina-core</artifactId> <version>1.1.7</version> </dependency> <dependency> <groupId>dom4j</groupId> <artifactId>dom4j</artifactId> <version>1.6.1</version> </dependency> <dependency> <groupId>com.microsoft.sqlserver</groupId> <artifactId>msjdbc</artifactId> <version>1.0</version> </dependency> <!-- Open Flash Chart start--> <dependency> <groupId>jofc2</groupId> <artifactId>jofc2</artifactId> <version>1.0.0</version> </dependency> <dependency> <groupId>com.thoughtworks.xstream</groupId> <artifactId>xstream</artifactId> <version>1.3.1</version> </dependency> <!-- Open Flash Chart end--> <dependency> <groupId>jcifs</groupId> <artifactId>jcifs</artifactId> <version>1.3.14</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.2-FINAL</version> </dependency> <!-- <dependency> <groupId>opensymphony</groupId> <artifactId>sitemesh</artifactId> <version>2.4.2</version> </dependency> --> <dependency> <artifactId>solr-solrj</artifactId> <groupId>org.apache.solr</groupId> <version>3.3.0</version> <scope>compile</scope> </dependency> </dependencies> </dependencyManagement> <repositories> <repository> <id>zz91_repository</id> <name>zz91 local artifactory</name> <url>http://192.168.2.178:8080/artifactory/repo</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>zz91_pluginRepository</id> <name>zz91 local artifactory</name> <url>http://192.168.2.178:8080/artifactory/plugins-releases</url> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> </pluginRepositories> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>${java.source.version}</source> <target>${java.target.version}</target> <encoding>${encoding}</encoding> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <executions> <execution> <id>attach-sources</id> <goals> <goal>jar</goal> </goals> </execution> </executions> <configuration> <attach>true</attach> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <configuration> <charset>${encoding}</charset> <encoding>${encoding}</encoding> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <excludes> <exclude>log4j.properties</exclude> </excludes> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <archive> <addMavenDescriptor>false</addMavenDescriptor> </archive> <webResources> <resource> <!-- this is relative to the pom.xml directory --> <directory>src/main/resources/${package.environment}</directory> <targetPath>WEB-INF/classes</targetPath> <filtering>true</filtering> </resource> </webResources> </configuration> </plugin> <!-- <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <configuration> <encoding>UTF-8</encoding> </configuration> </plugin> --> </plugins> <resources> <resource> <directory>src/main/resources</directory> <includes> <include>**/*</include> </includes> <excludes> <exclude>${package.environment}/*</exclude> </excludes> <filtering>true</filtering> </resource> <resource> <directory>src/main/resources/${package.environment}</directory> <includes> <include>**/*</include> </includes> <filtering>true</filtering> </resource> </resources> <testResources> <testResource> <directory>src/test/java</directory> <includes> <include>**/*</include> </includes> </testResource> <testResource> <directory>src/test/resources</directory> <includes> <include>**/*</include> </includes> </testResource> </testResources> </build> <profiles> <profile> <id>dev</id> <properties> <package.environment>dev</package.environment> </properties> </profile> <profile> <id>production</id> <properties> <package.environment>production</package.environment> <jdbc.location>file:/usr/tools/config/db/db-ast.properties</jdbc.location> </properties> </profile> <profile> <id>test</id> <properties> <package.environment>test</package.environment> <jdbc.location>file:/usr/tools/config/db/db-ast.properties</jdbc.location> </properties> </profile> </profiles> </project>
下面为web项目和common,service.persist建立对应的pom文件并且,建立好父子依赖关系
myMainWeb web项目的pom文件
View Code
<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"> <parent> <groupId>cn.myBussiness</groupId> <artifactId>parent</artifactId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <groupId>cn.myBussiness</groupId> <artifactId>myMainWeb</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>myMainWeb</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>cn.myBussiness</groupId> <artifactId>persist</artifactId> </dependency> <dependency> <groupId>cn.myBussiness</groupId> <artifactId>service</artifactId> </dependency> <dependency> <groupId>cn.myBussiness</groupId> <artifactId>common</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> </dependency> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity</artifactId> </dependency> <dependency> <groupId>velocity-tools</groupId> <artifactId>velocity-tools</artifactId> </dependency> <dependency> <groupId>net.sf.json-lib</groupId> <artifactId>json-lib</artifactId> <classifier>jdk15</classifier> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> </dependency> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> </dependency> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> </dependency> <dependency> <groupId>commons-digester</groupId> <artifactId>commons-digester</artifactId> </dependency> <dependency> <groupId>javax.mail</groupId> <artifactId>mail</artifactId> </dependency> <dependency> <groupId>quartz</groupId> <artifactId>quartz</artifactId> </dependency> <dependency> <groupId>org.tuckey</groupId> <artifactId>urlrewritefilter</artifactId> </dependency> <!-- rpc begin <dependency> <groupId>com.usharp</groupId> <artifactId>usharp-common</artifactId> </dependency> <dependency> <groupId>com.usharp</groupId> <artifactId>usharp-rpc</artifactId> </dependency> <dependency> <groupId>org.apache.mina</groupId> <artifactId>mina-core</artifactId> </dependency> --> <!--rpc end--> <!-- Open Flash Chart start--> <dependency> <groupId>jofc2</groupId> <artifactId>jofc2</artifactId> </dependency> <dependency> <groupId>com.thoughtworks.xstream</groupId> <artifactId>xstream</artifactId> </dependency> <!-- Open Flash Chart end--> <dependency> <groupId>org.jsoup</groupId> <artifactId>jsoup</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>tomcat-maven-plugin</artifactId> <configuration> <path>/</path> <port>9090</port> </configuration> </plugin> </plugins> </build> </project>
common项目的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/xsd/maven-4.0.0.xsd"> <parent> <groupId>cn.myBussiness</groupId> <artifactId>parent</artifactId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <groupId>cn.myBussiness</groupId> <artifactId>common</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <name>common</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>tomcat-maven-plugin</artifactId> <configuration> <path>/</path> <port>9090</port> </configuration> </plugin> </plugins> </build> </project>
service项目
<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"> <parent> <artifactId>parent</artifactId> <groupId>cn.myBussiness</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <groupId>cn.myBussiness</groupId> <artifactId>service</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <name>service</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>cn.myBussiness</groupId> <artifactId>common</artifactId> </dependency> <dependency> <groupId>cn.myBussiness</groupId> <artifactId>persist</artifactId> </dependency> </dependencies> </project>
persist项目的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/xsd/maven-4.0.0.xsd"> <parent> <groupId>cn.myBussiness</groupId> <artifactId>parent</artifactId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <groupId>cn.myBussiness</groupId> <artifactId>persist</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <name>persist</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>cn.myBussiness</groupId> <artifactId>common</artifactId> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </dependency> <dependency> <groupId>c3p0</groupId> <artifactId>c3p0</artifactId> </dependency> <dependency> <groupId>org.apache.ibatis</groupId> <artifactId>ibatis-sqlmap</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> </dependency> </dependencies> </project>
解释一下common web persist 和service的关系
web要依赖其余三个
service要依赖common和persist persist依赖common
这样 项目之间的功能都已经确定完毕,依赖关系也确定完毕.
下一节开始web.xml 等配置文件的配置
奔跑...