码迷,mamicode.com
首页 > 其他好文 > 详细

idea创建父工程子工程与子模块

时间:2018-01-22 00:08:02      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:项目   eclipse   localhost   log4j   plugins   conf   关系   组件   mpi   

 

?首先,我们创建一个新的工作空间

点击File ->New-Project…,弹出以下界面

技术分享图片

?点击Next

技术分享图片

?点击Finish,进入到一个新的工作空间

技术分享图片

?创建queen-parent工程

点击File ->New->Module…,进入以下界面

技术分享图片

?点击Next,填写组织名称和项目名称,以及版本号(GAV)

技术分享图片

?点击Next

技术分享图片

?点击Next,父工程最后一步,给Module取名及选择工作目录

技术分享图片

?点击Finish,完成,如图:

技术分享图片

?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.queen.parent</groupId>
	<artifactId>queen-parent</artifactId>
	<version>1.0-SNAPSHOT</version>
	<packaging>pom</packaging>

	<!-- 集中定义依赖版本号 -->
	<properties>
		<junit.version>4.10</junit.version>
		<spring.version>4.1.3.RELEASE</spring.version>
		<mybatis.version>3.2.8</mybatis.version>
		<mybatis.spring.version>1.2.2</mybatis.spring.version>
		<mybatis.paginator.version>1.2.15</mybatis.paginator.version>
		<mysql.version>5.1.32</mysql.version>
		<slf4j.version>1.6.4</slf4j.version>
		<jackson.version>2.4.2</jackson.version>
		<druid.version>1.0.9</druid.version>
		<httpclient.version>4.3.5</httpclient.version>
		<jstl.version>1.2</jstl.version>
		<servlet-api.version>2.5</servlet-api.version>
		<jsp-api.version>2.0</jsp-api.version>
		<joda-time.version>2.5</joda-time.version>
		<commons-lang3.version>3.3.2</commons-lang3.version>
		<commons-io.version>1.3.2</commons-io.version>
	</properties>

	<dependencyManagement>
		<dependencies>
			<!-- 单元测试 -->
			<dependency>
				<groupId>junit</groupId>
				<artifactId>junit</artifactId>
				<version>${junit.version}</version>
				<scope>test</scope>
			</dependency>

			<!-- Spring -->
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-context</artifactId>
				<version>${spring.version}</version>
			</dependency>
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-beans</artifactId>
				<version>${spring.version}</version>
			</dependency>
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-webmvc</artifactId>
				<version>${spring.version}</version>
			</dependency>
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-jdbc</artifactId>
				<version>${spring.version}</version>
			</dependency>
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-aspects</artifactId>
				<version>${spring.version}</version>
			</dependency>

			<!-- Mybatis -->
			<dependency>
				<groupId>org.mybatis</groupId>
				<artifactId>mybatis</artifactId>
				<version>${mybatis.version}</version>
			</dependency>
			<dependency>
				<groupId>org.mybatis</groupId>
				<artifactId>mybatis-spring</artifactId>
				<version>${mybatis.spring.version}</version>
			</dependency>
			<!-- 分页助手 -->
			<dependency>
				<groupId>com.github.pagehelper</groupId>
				<artifactId>pagehelper</artifactId>
				<version>3.7.5</version>
			</dependency>
			<dependency>
				<groupId>com.github.jsqlparser</groupId>
				<artifactId>jsqlparser</artifactId>
				<version>0.9.1</version>
			</dependency>
			<!-- 通用Mapper -->
			<dependency>
				<groupId>com.github.abel533</groupId>
				<artifactId>mapper</artifactId>
				<version>2.3.4</version>
			</dependency>

			<!-- MySql -->
			<dependency>
				<groupId>mysql</groupId>
				<artifactId>mysql-connector-java</artifactId>
				<version>${mysql.version}</version>
			</dependency>

			<dependency>
				<groupId>org.slf4j</groupId>
				<artifactId>slf4j-log4j12</artifactId>
				<version>${slf4j.version}</version>
			</dependency>

			<!-- Jackson Json处理工具包 -->
			<dependency>
				<groupId>com.fasterxml.jackson.core</groupId>
				<artifactId>jackson-databind</artifactId>
				<version>${jackson.version}</version>
			</dependency>

			<!-- 连接池 -->
			<dependency>
				<groupId>com.jolbox</groupId>
				<artifactId>bonecp-spring</artifactId>
				<version>0.8.0.RELEASE</version>
			</dependency>

			<!-- httpclient -->
			<dependency>
				<groupId>org.apache.httpcomponents</groupId>
				<artifactId>httpclient</artifactId>
				<version>${httpclient.version}</version>
			</dependency>

			<!-- JSP相关 -->
			<dependency>
				<groupId>jstl</groupId>
				<artifactId>jstl</artifactId>
				<version>${jstl.version}</version>
			</dependency>
			<dependency>
				<groupId>javax.servlet</groupId>
				<artifactId>servlet-api</artifactId>
				<version>${servlet-api.version}</version>
				<scope>provided</scope>
			</dependency>
			<dependency>
				<groupId>javax.servlet</groupId>
				<artifactId>jsp-api</artifactId>
				<version>${jsp-api.version}</version>
				<scope>provided</scope>
			</dependency>

			<!-- 时间操作组件 -->
			<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>

		</dependencies>
	</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.2</version>
				<configuration>
					<source>1.7</source>
					<target>1.7</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>

注意:项目的打包方式为pom

?创建公用工程queen-common

点击File->New->Module…,进入以下界面,请按照下图红色框框进行选中

技术分享图片

?点击Next

技术分享图片

?点击Next

技术分享图片

?点击Next

技术分享图片

?点击Finish,创建成功

技术分享图片

?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.queen.common</groupId>
	<artifactId>queen-common</artifactId>
	<parent>
		<groupId>com.queen.parent</groupId>
		<artifactId>queen-parent</artifactId>
		<version>1.0-SNAPSHOT</version>
	</parent>
</project>

注意:项目的打包方式为jar和父项目有所不同

?创建queen-manage

跟前面创建queen-parent步骤类似,就不再赘述了,注意:下面打包方式为pom

技术分享图片

技术分享图片

?点击Finish,创建成功

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.queen.manage</groupId>
    <artifactId>queen-manage</artifactId>
    <packaging>pom</packaging>
    <parent>
        <groupId>com.queen.parent</groupId>
        <artifactId>queen-parent</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
</project>

?接下来我们创建工程queen-manage的子模块工程queen-manage-pojo

技术分享图片

?点击Next

技术分享图片

?点击Next

技术分享图片

?点击Next

技术分享图片

?点击Finish完成

紧接着我们依次创建queen-manage-mapper,queen-manage-service,queen-manage-controller工程,步骤跟queen-manage-pojo一样。

注意:在我们创建queen-manage-controller时,打包方式要选择war。

?最终我们新建的所有工程如下:

技术分享图片

?现在我们要整理一下子工程之间的依赖关系

queen-manage-controller-依赖-queen-manage-service-依赖-queen-manage-mapper-依赖-queen-manage-pojo

上面可知,我们的依赖关系如此。

那我们修改一下pom文件

在queen-manage-mapper的pom文件中加入queen-manage-pojo的坐标

<dependency>
	<groupId>com.queen.manage</groupId>
	<artifactId>queen-manage-pojo</artifactId>
	<version>0.0.1-SNAPSHOT</version>
</dependency>

在queen-manage-service的pom文件中加入queen-manage-mapper的坐标

<dependency>
	<groupId>com.queen.manage</groupId>
	<artifactId>queen-manage-mapper</artifactId>
	<version>0.0.1-SNAPSHOT</version>
</dependency>

在queen-manage-controller的pom文件中加入queen-manage-service的坐标

<dependency>
	<groupId>com.queen.manage</groupId>
	<artifactId>queen-manage-service</artifactId>
	<version>0.0.1-SNAPSHOT</version>
</dependency>

?各个工程中导入依赖

在queen-manage-controller工程的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>
  <parent>
    <groupId>com.queen.manage</groupId>
    <artifactId>queen-manage</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>queen-manage-controller</artifactId>
  <packaging>war</packaging>
  <dependencies>
		<dependency>
			<groupId>com.queen.manage</groupId>
			<artifactId>queen-manage-service</artifactId>
			<version>1.0.0-SNAPSHOT</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-jdbc</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-aspects</artifactId>
		</dependency>
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis-spring</artifactId>
		</dependency>
		<!-- MySql -->
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
		</dependency>
		<!-- Jackson Json处理工具包 -->
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-databind</artifactId>
		</dependency>
		<!-- 连接池 -->
		<dependency>
			<groupId>com.jolbox</groupId>
			<artifactId>bonecp-spring</artifactId>
		</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>
			<version>1.3.1</version>
		</dependency>
		<!-- 时间操作组件 -->
		<dependency>
			<groupId>joda-time</groupId>
			<artifactId>joda-time</artifactId>
		</dependency>
	</dependencies>
</project>

在queen-manage-service工程的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>
  <parent>
    <groupId>com.queen.manage</groupId>
    <artifactId>queen-manage</artifactId>
    <version>1.0.0-SNAPSHOT</version>
  </parent>
  <artifactId>queen-manage-service</artifactId>
  <dependencies>
		<dependency>
			<groupId>com.queen.manage</groupId>
			<artifactId>queen-manage-mapper</artifactId>
			<version>0.0.1-SNAPSHOT</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
		</dependency>
		<!-- 分页助手 -->
		<dependency>
			<groupId>com.github.pagehelper</groupId>
			<artifactId>pagehelper</artifactId>
		</dependency>
		<dependency>
			<groupId>com.github.jsqlparser</groupId>
			<artifactId>jsqlparser</artifactId>
		</dependency>
	</dependencies>
</project>

在queen-manage-mapper工程的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>
  <parent>
    <groupId>com.queen.manage</groupId>
    <artifactId>queen-manage</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>queen-manage-mapper</artifactId>
  <dependencies>
		<dependency>
			<groupId>com.queen.manage</groupId>
			<artifactId>queen-manage-pojo</artifactId>
			<version>0.0.1-SNAPSHOT</version>
		</dependency>
		<!-- Mybatis -->
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis</artifactId>
		</dependency>
		<!-- 通用Mapper -->
		<dependency>
			<groupId>com.github.abel533</groupId>
			<artifactId>mapper</artifactId>
			<exclusions>
				<exclusion>
					<artifactId>persistence-api</artifactId>
					<groupId>javax.persistence</groupId>
				</exclusion>
			</exclusions>
		</dependency>
	</dependencies>
</project>

在queen-manage-pojo工程的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>
  <parent>
    <groupId>com.queen.manage</groupId>
    <artifactId>queen-manage</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>queen-manage-pojo</artifactId>
  <dependencies>
		<dependency>
			<groupId>javax.persistence</groupId>
			<artifactId>persistence-api</artifactId>
			<version>1.0</version>
		</dependency>
	</dependencies>
</project>

在queen-manage工程的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>
	<parent>
		<groupId>com.queen.parent</groupId>
		<artifactId>queen-parent</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</parent>
	<groupId>com.queen.manage</groupId>
	<artifactId>queen-manage</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>pom</packaging>
	<modules>
		<module>queen-manage-pojo</module>
		<module>queen-manage-mapper</module>
		<module>queen-manage-service</module>
		<module>queen-manage-web</module>
	</modules>
	<dependencies>
		<dependency>
			<groupId>com.queen.common</groupId>
			<artifactId>queen-common</artifactId>
			<version>0.0.1-SNAPSHOT</version>
		</dependency>
		<!-- 单元测试 -->
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
		</dependency>
		<!-- Apache工具组件 -->
		<dependency>
			<groupId>org.apache.commons</groupId>
			<artifactId>commons-lang3</artifactId>
		</dependency>
		<dependency>
			<groupId>org.apache.commons</groupId>
			<artifactId>commons-io</artifactId>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<!-- 配置Tomcat插件 -->
			<plugin>
				<groupId>org.apache.tomcat.maven</groupId>
				<artifactId>tomcat7-maven-plugin</artifactId>
				<configuration>
					<port>8080</port>
					<path>/</path>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>

?运行工程,这里我们使用Maven Tomcat Plugin运行web项目

点击主界面右上角技术分享图片,进入以下界面

技术分享图片

技术分享图片

注意:运行之前,每个工程需要clean和install一下 ,否则启动不了,如果你不知道IDEA如何使用Maven的clean功能,请参考这篇文章《IntelliJ IDEA教程之如何clean或者install Maven项目》

web.xml配置如下

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	id="WebApp_ID" version="2.5">
	<display-name>queen-manage</display-name>
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>

</web-app>

index.jsp文件如下:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>index</title>
</head>
<body>
	Welcome:queen
</body>

?点击主界面右上角绿色三角形运行项目

运行起来之后,我们访问一下服务http://localhost:8080/index.jsp

技术分享图片

至此,我们关于IntelliJ IDEA教程之Maven工程多模块继承和聚合创建(详解)介绍完毕。其实博主也写过一篇关于Eclipse下如何创建聚合工程,具体可以参考《Eclipse下Maven工程多模块继承和聚合创建(详解)》这篇文章。

博客地址:http://www.marsitman.com/idea/intellij-idea-create-maven-union.html
版权声明:本文为博主原创文章,允许转载,但转载必须标明出处。

 

idea创建父工程子工程与子模块

标签:项目   eclipse   localhost   log4j   plugins   conf   关系   组件   mpi   

原文地址:https://www.cnblogs.com/hzdzkjdxygz/p/8325779.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!