使用IntelliJ IDEA 12建立Maven多模块项目

使用Maven管理项目时,每每须要建立多个模块,模块之间存在相互引用的关系。对于Maven的依赖,也须要专门建立一个模块来管理依赖项。例如对于一个项目,能够建立一个config模块来管理Maven依赖项,建立一个common模块来管理POJO类,建立一个server来管理业务逻辑及数据库操做类,建立一个web模块来组织Web文件,如HTML,JSP等。下图是一个Maven多模块管理的案例项目结构: java

使用IntelliJ IDEA12建立Maven多模块项目

简单说一下建立过程: linux

1.首先建立一个空项目:Demo,New Project对话框左侧选择Maven Module(IDEA中的Module对应于Eclipse中的Project),以下图所示: web

使用IntelliJ IDEA12建立Maven多模块项目

2.选择建立项目的模板,能够不使用模块,建立出来的项目会多出src目录,手动删除src目录便可,或者选择一个blank模板(要使用模板,则须要勾选“Create from archetype”),直接建立一个空项目,操做以下图所示: spring

3.在项目名字上右击->New->Module,填写子项目(模块)名称,选择Maven Project便可,若是不是Web模块,则能够使用模板建立(即不勾选“Create from archetype”),普通项目须要有src目录,src下分为main和test,main下有java和resources目录,java类就放在java目录下。 数据库

4.建立web目录是,须要使用webapp模板,勾选“Create from archetype”,选择maven-archetype-webapp模板便可,以下图: apache

使用IntelliJ IDEA12建立Maven多模块项目

通过这几个步骤,一个Maven管理的多模块(子项目)项目结构就建成了。能够将须要使用的Maven依赖项放到config模块(子项目)中,其余模块从config引用便可,具体操做见Maven相关教程。 app

打开项目时,能够使用IntelliJ IDEA直接打开主项目的pom.xml文件便可导入Maven项目,操做以下图所示: webapp

使用IntelliJ IDEA12建立Maven多模块项目

IntelliJ IDEA 的详细介绍请点这里 maven

IntelliJ IDEA 的下载地址请点这里 字体


<!-- 新增仓库 -->
<repositories>
<repository>
<id>oschina Releases</id>
<name>oschina Releases</name>
<url>http://maven.oschina.net/content/groups/public</url>
</repository>
<repository>
<id>apache-repo</id>
<name>apache Repository</name>
<url>https://repository.apache.org/content/groups/public/</url>
</repository>
<repository>
<id>java-repo</id>
<name>java Repository</name>
<url>http://download.java.net/maven/2/</url>
</repository>
<repository>
<id>springsource-repo</id>
<name>SpringSource Repository</name>
<url>http://repo.spring.io/release/</url>
</repository>
<repository>
<id>springsource-repo-snapshot</id>
<name>SpringSource Repository</name>
<url>http://repo.spring.io/snapshot/</url>
</repository>
<repository>
<id>cloudhopper</id>
<name>Repository for Cloudhopper</name>
<url>http://maven.cloudhopper.com/repos/third-party/</url>
</repository>
<repository>
<id>jboss-repo-releases</id>
<name>Jboss Repository</name>
<url>https://repository.jboss.org/nexus/content/repositories/releases/</url>
</repository>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://repo.maven.apache.org/maven2</url>
</repository>
<repository>
<id>maven-repo1</id>
<name>maven-repo1</name>
<layout>default</layout>
<url>http://repo1.maven.org/maven2/</url>
</repository>
<repository>
<id>sourceforge-releases</id>
<name>Sourceforge Releases</name>
<url>https://oss.sonatype.org/content/repositories/sourceforge-releases</url>
</repository>
</repositories>



相关阅读:

IntelliJ IDEA: 字体美化(anti-aliased)和字体添加 http://www.linuxidc.com/Linux/2013-11/92609.htm

IntelliJ IDEA 12 建立Web项目图文详细教程 http://www.linuxidc.com/Linux/2013-05/84213.htm

用IntelliJ IDEA开发Android程序图文教程 http://www.linuxidc.com/Linux/2013-03/81471.htm

IntelliJ IDEA 12开发haXe NME应用配置指南 http://www.linuxidc.com/Linux/2013-01/77227.htm

IntelliJ IDEA运行Play Framework的test mode http://www.linuxidc.com/Linux/2013-07/87694.htm

Ubuntu 13.04 安装IntelliJ IDEA 12 http://www.linuxidc.com/Linux/2013-11/93014.htm

相关文章
相关标签/搜索