maven提供的41个骨架原型分别是:
1: appfuse-basic-jsf (创建一个基于Hibernate,Spring和JSF的Web应用程序的原型)
2: appfuse-basic-spring(创建一个基于Hibernate,Spring和Spring MVC的Web应用程序的原型)
3: appfuse-basic-struts(创建一个基于Hibernate,Spring和Struts 2的Web应用程序的原型)
4: appfuse-basic-tapestry(创建一个基于Hibernate,Spring 和 Tapestry 4的Web应用程序的原型)
5: appfuse-core(创建一个基于Hibernate,Spring 和 XFire的jar应用程序的原型)
6: appfuse-modular-jsf(创建一个基于Hibernate,Spring和JSF的模块化应用原型)
7: appfuse-modular-spring(创建一个基于Hibernate, Spring 和 Spring MVC 的模块化应用原型)
8: appfuse-modular-struts(创建一个基于Hibernate, Spring 和 Struts 2 的模块化应用原型)
9: appfuse-modular-tapestry (创建一个基于 Hibernate, Spring 和 Tapestry 4 的模块化应用原型)
10: maven-archetype-j2ee-simple(一个简单的J2EE的Java应用程序)
11: maven-archetype-marmalade-mojo(一个Maven的 插件开发项目 using marmalade)
12: maven-archetype-mojo(一个Maven的Java插件开发项目)
13: maven-archetype-portlet(一个简单的portlet应用程序)
14: maven-archetype-profiles()
15:maven-archetype-quickstart()
16: maven-archetype-site-simple(简单的网站生成项目)
17: maven-archetype-site(更复杂的网站项目)
18:maven-archetype-webapp(一个简单的Java Web应用程序)
19: jini-service-archetype(Archetype for Jini service project creation)
20: softeu-archetype-seam(JSF+Facelets+Seam Archetype)
21: softeu-archetype-seam-simple(JSF+Facelets+Seam (无残留) 原型)
22: softeu-archetype-jsf(JSF+Facelets 原型)
23: jpa-maven-archetype(JPA 应用程序)
24: spring-osgi-bundle-archetype(Spring-OSGi 原型)
25: confluence-plugin-archetype(Atlassian 聚合插件原型)
26: jira-plugin-archetype(Atlassian JIRA 插件原型)
27: maven-archetype-har(Hibernate 存档)
28: maven-archetype-sar(JBoss 服务存档)
29: wicket-archetype-quickstart(一个简单的Apache Wicket的项目)
30: scala-archetype-simple(一个简单的scala的项目)
31: lift-archetype-blank(一个 blank/empty liftweb 项目)
32: lift-archetype-basic(基本(liftweb)项目)
33: cocoon-22-archetype-block-plain([http://cocoapacorg2/maven-plugins/])
34: cocoon-22-archetype-block([http://cocoapacorg2/maven-plugins/])
35:cocoon-22-archetype-webapp([http://cocoapacorg2/maven-plugins/])
36: myfaces-archetype-helloworld(使用MyFaces的一个简单的原型)
37: myfaces-archetype-helloworld-facelets(一个使用MyFaces和Facelets的简单原型)
38: myfaces-archetype-trinidad(一个使用MyFaces和Trinidad的简单原型)
39: myfaces-archetype-jsfcomponents(一种使用MyFaces创建定制JSF组件的简单的原型)
40: gmaven-archetype-basic(Groovy的基本原型)
41: gmaven-archetype-mojo(Groovy mojo 原型)
(41中骨架原文链接:http://www.cnblogs.com/iusmile/archive/2012/11/14/2770118.html)
一.工程目录
先看一下目录关系
taotao-parent(父工程管理jar包的版本)
|--taotao-common(把通用的工具类打包)
|--taotao-manager(继承父工程)
|-taotao-manager-pojo
|-taotao-manager-dao
|-taotao-manager-service
|-taotao-manager-web(war包)
taotao-parent 为项目的父工程,用来管理jar包及版本
taotao-common为通用工程,继承父工程,就是把通用的工具类打包
taotao-manager为开发工程,同样继承父工程
其中,taotao-manager-pojo,taotao-manager-dao,taotao-manager-service和taotao-manager-web均为开发工程的一个子模块,依赖于开发工程taotao-manager
前3个子模块打成jar包,taotao-manager-web打成war包
二.创建工程
1.先创建一个空工程,步骤如下:
File——>new——>project
选择Empty——>next
填写工程名称和位置,点击finnish,完成了空工程的创建
2.创建父工程 taotao-parent,步骤如下:
File——>New——>Module
点maven,勾选archetype,选quickstart这项,然后Next下一步
填写GroupId,一般为组织名称;填写ArtifactId,为项目名称
选择本地maven目录及maven配置文件
填写项目名称及位置,点Finish,父工程创建完成
等待生成pom文件,修改打包方式为pom,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"> <modelVersion>4.0.0</modelVersion> <groupId>com.slx</groupId> <artifactId>taotao-parent</artifactId> <version>1.0-SNAPSHOT</version> <packaging>pom</packaging> <name>taotao-parent</name> <url>http://maven.apache.org</url> <!-- 集中定义依赖版本号 --> <properties> <junit.version>4.12</junit.version> <spring.version>4.1.3.RELEASE</spring.version> <mybatis.version>3.2.8</mybatis.version> <!--省略,自行添加--> </properties> <dependencyManagement> <dependencies> <!-- 时间操作组件 --> <dependency> <groupId>joda-time</groupId> <artifactId>joda-time</artifactId> <version>${joda-time.version}</version> </dependency> <!-- Apache工具组件 --> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>${commons-lang3.version}</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-io</artifactId> <version>${commons-io.version}</version> </dependency> <dependency> <groupId>commons-net</groupId> <artifactId>commons-net</artifactId> <version>${commons-net.version}</version> </dependency> <!--省略,自行添加--> </dependencyManagement> <build> <finalName>${project.artifactId}</finalName> <plugins> <!-- 资源文件拷贝插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.7</version> <configuration> <encoding>UTF-8</encoding> </configuration> </plugin> <!-- java编译插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.5.1</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> <pluginManagement> <plugins> <!-- 配置Tomcat插件 --> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> </plugin> </plugins> </pluginManagement> </build> </project>
3.创建通用工程taotao-common
File——>New——>Module
点maven后直接next下一步
继承taotao-parent,填写ArtifactId,然后next下一步
填写通用模块名称,点finish,通用模块创建完成
开发模块taotao-manager与通用模块创建方式一致
taotao-common的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"> <parent> <artifactId>taotao-parent</artifactId> <groupId>com.slx</groupId> <version>1.0-SNAPSHOT</version> <relativePath>../taotao-parent/pom.xml</relativePath> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>taotao-common</artifactId> <packaging>jar</packaging> <name>taotao-common</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <!-- 添加依赖 --> <dependencies> <!-- 时间操作组件 --> <dependency> <groupId>joda-time</groupId> <artifactId>joda-time</artifactId> </dependency> <!-- Apache工具组件 --> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> </dependency> <!--省略,自行添加--> </dependency> </dependencies> </project>
taotao-manager的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"> <parent> <artifactId>taotao-parent</artifactId> <groupId>com.slx</groupId> <version>1.0-SNAPSHOT</version> <relativePath>../taotao-parent/pom.xml</relativePath> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>taotao-manager</artifactId> <packaging>pom</packaging> <name>taotao-manager</name> <url>http://maven.apache.org</url> <modules> <module>taotao-manager-pojo</module> <module>taotao-manager-dao</module> <module>taotao-manager-service</module> <module>taotao-manager-web</module> </modules> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <!-- 添加依赖 --> <dependencies> <dependency> <groupId>com.slx</groupId> <artifactId>taotao-common</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies> <build> <!-- 配置插件 --> <plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <configuration> <port>8080</port> <path>/</path> </configuration> </plugin> </plugins> </build> </project>
4.创建开发模块下的子模块,分两类介绍,taotao-manager-pojo,taotao-manager-dao,taotao-manager-service创建方式一样,taotao-manager-web的创建有点差别
1)以taotao-manager-pojo为例
File——>new——>module
选maven——>勾选archetype——>选quickstart这项——>点next
继承taotao-manager,填写ArtifactId
这里注意改写路径,点finish,一个子模块创建完成
taotao-manager-pojo的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/xsd/maven-4.0.0.xsd"> <parent> <artifactId>taotao-manager</artifactId> <groupId>com.slx</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>taotao-manager-pojo</artifactId> <packaging>jar</packaging> <name>taotao-manager-pojo</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> </project>
taotao-manager-dao的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/xsd/maven-4.0.0.xsd"> <parent> <artifactId>taotao-manager</artifactId> <groupId>com.slx</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>taotao-manager-dao</artifactId> <packaging>jar</packaging> <name>taotao-manager-dao</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <!-- 依赖与pojo子模块 --> <dependency> <groupId>com.slx</groupId> <artifactId>taotao-manager-pojo</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <!-- Mybatis --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> </dependency> <dependency> <groupId>com.github.miemiedev</groupId> <artifactId>mybatis-paginator</artifactId> </dependency> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> </dependency> <!-- MySql --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <!-- 连接池 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> </dependency> </dependencies> </project>
taotao-manager-service的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/xsd/maven-4.0.0.xsd"> <parent> <artifactId>taotao-manager</artifactId> <groupId>com.slx</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>taotao-manager-service</artifactId> <packaging>jar</packaging> <name>taotao-manager-service</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>com.slx</groupId> <artifactId>taotao-manager-dao</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> </dependency> </dependencies> </project>
2)taotao-manager-web创建
同样File——>New——>Module
只不过这里选择webapp这项(唯一不同的地方,其他地方类似),点next下一步
同样继承taotao-manager
同样需要改写路径,点击finish,taotao-manager-web子模块创建完成
taotao-manager-web的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"> <parent> <artifactId>taotao-manager</artifactId> <groupId>com.slx</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>taotao-manager-web</artifactId> <packaging>war</packaging> <name>taotao-manager-web Maven Webapp</name> <url>http://maven.apache.org</url> <!-- 添加依赖 --> <dependencies> <dependency> <groupId>com.slx</groupId> <artifactId>taotao-manager-service</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <!-- JSP相关 --> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifactId> <scope>provided</scope> </dependency> <!-- 文件上传组件 --> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> </dependency> </dependencies> <build> <finalName>taotao-manger-web</finalName> </build> </project>
5.接下来运行工程使用:tomcat7:run
右上角Edit Configurations
选maven
需要把taotao-parent等需要安装的都安装到本地仓库。
最后运行,如下图所示,就说明跑通了!
总结:
之前看别人的博客,有选择portlet项,自己弄死活跑不通。
taotao-parent,taotao-manager-pojo,taotao-manager-dao,taotao-manager-service选择quickstart那项;
taotao-common,taotao-manager啥都不选;
taotao-manager-web选择webapp那项。
还要注意打包方式,jar,pom,war