概述
首发网址:Idea项目--多模块项目(淘淘商城)_IT利刃出鞘的博客-CSDN博客
目录结构
工程目录—taotao
选择Empty project,next
输入项目名称,创建项目
父工程—taotao-parent
使用“maven-archetype-quickstart”模板原型创建工程。
file=> Project Structure=> Project Settings=> Modules=> 中间一栏最上边“+”=> new Module
创建Maven工程
注:maven-archetype-quickstart(简单工程)
给Maven工程起个名字,完成
配置pom.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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.taotao</groupId>
<artifactId>taotao-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<name>taotao-parent</name>
<packaging>pom</packaging>
<properties>
<junit.version>4.12</junit.version>
<spring.version>4.3.12.RELEASE</spring.version>
<mybatis.version>3.4.5</mybatis.version>
<mybatis.spring.version>1.3.1</mybatis.spring.version>
<mybatis.paginator.version>1.2.15</mybatis.paginator.version>
<mysql.version>5.1.41</mysql.version>
<slf4j.version>1.6.4</slf4j.version>
<jackson.version>2.9.1</jackson.version>
<druid.version>1.0.29</druid.version>
<httpclient.version>4.5.3</httpclient.version>
<jstl.version>1.2</jstl.version>
<jsp-api.version>2.2</jsp-api.version>
<joda-time.version>2.9.9</joda-time.version>
<commons-lang3.version>3.5</commons-lang3.version>
<commons-io.version>2.5</commons-io.version>
<commons-net.version>3.3</commons-net.version>
<pagehelper.version>5.1.2</pagehelper.version>
<jsqlparser.version>1.1</jsqlparser.version>
<commons-fileupload.version>1.3.2</commons-fileupload.version>
<jedis.version>2.9.0</jedis.version>
<solrj.version>7.1.0</solrj.version>
<hutool.version>3.1.2</hutool.version>
<servlet-api.version>4.0.0</servlet-api.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>commons-io</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>
<!-- Jackson Json处理工具包 -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<!-- httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
<!-- 单元测试 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!-- 日志处理 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.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.miemiedev</groupId>
<artifactId>mybatis-paginator</artifactId>
<version>${mybatis.paginator.version}</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>${pagehelper.version}</version>
</dependency>
<!-- MySql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<!-- 连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</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>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- JSP相关 -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>${jstl.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet-api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>${jsp-api.version}</version>
<scope>provided</scope>
</dependency>
<!-- 文件上传组件 -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>${commons-fileupload.version}</version>
</dependency>
<!-- Redis客户端 -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>${jedis.version}</version>
</dependency>
<!-- solr客户端 -->
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>${solrj.version}</version>
</dependency>
<!-- hutool工具包 -->
<dependency>
<groupId>com.xiaoleilu</groupId>
<artifactId>hutool-core</artifactId>
<version>${hutool.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.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>
<configuration>
<port>8080</port>
<path>/</path>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
通用工程—taotao-common
使用“maven-archetype-portlet”创建新模块
file=> Project Structure=> Project Settings=> Modules=> 中间一栏最上边“+”=> new Module
(有人用file=>new->Module,这种方法很容易在已有的taotao-parent子目录下创建工程,达不到预期)
注:maven-archetype-portlet (一个简单的portlet应用程序)
taotao-common的pom.xml如下。(注意项目的打包方式为jar,和父项目有所不同)
<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.taotao</groupId>
<artifactId>taotao-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<!-- 本groupId可省略 -->
<groupId>com.taotao</groupId>
<artifactId>taotao-common</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<!-- 依赖工具类的jar包 -->
<dependencies>
<!-- 时间操作组件 -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
<!-- Apache工具组件 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
</dependency>
<!-- Jackson Json处理工具包 -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<!-- httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<!-- 单元测试 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<!-- 日志处理 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
</dependencies>
</project>
开发工程—taotao-manager
创建父模块taotao-manager
使用“maven-archetype-quickstart”或“maven-archetype-portlet”都可以,最后只保留pom.xml和taotao-manager.iml文件,其他删掉。
file=> Project Structure=> Project Settings=> Modules=> 中间一栏最上边“+”=> new Module
(有人用file=>new->Module,这种方法很容易在已有的taotao-parent子目录下创建工程,达不到预期)
各个模块的maven类型为
pom.xml:打包方式改为pom: <packaging> pom</packaging>
需要依赖taotao-common
taotao-manager的pom.xml为:
<?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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>taotao-parent</artifactId>
<groupId>com.taotao</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>
<modules>
<module>taotao-manager-pojo</module>
<module>taotao-manager-service</module>
<module>taotao-manager-mapper</module>
<module>taotao-manager-web</module>
</modules>
<!-- 依赖管理 -->
<dependencies>
<dependency>
<groupId>com.taotao</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>
开发工程—taotao-manager的子模块
右键“taotao-manager”=> New=> Module
使用“maven-archetype-quickstart”创建子模块pojo、service、mapper
选择
特别注意!!!
pom.xml中需要注意的:
- pojo的不用修改
- mapper的要引用pojo
- service要引用mapper
pojo的pom.xml:
<?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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>taotao-manager</artifactId>
<groupId>com.taotao</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../taotao-manager/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>taotao-manager-pojo</artifactId>
</project>
mapper的pom.xml:
<?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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>taotao-manager</artifactId>
<groupId>com.taotao</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../taotao-manager/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>taotao-manager-mapper</artifactId>
<packaging>jar</packaging>
<!-- 依赖管理 -->
<dependencies>
<dependency>
<groupId>com.taotao</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>
<!-- 单元测试 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
</project>
service的pom.xml:
<?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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>taotao-manager</artifactId>
<groupId>com.taotao</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../taotao-manager/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>taotao-manager-service</artifactId>
<packaging>jar</packaging>
<!-- 依赖管理 -->
<dependencies>
<dependency>
<groupId>com.taotao</groupId>
<artifactId>taotao-manager-mapper</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- Spring -->
<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-aop</artifactId>
</dependency>
<!-- 单元测试 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
</project>
Web子工程—taotao-manager-web
右键“taotao-manager”=> New=> Module
使用“maven-archetype-webapp” (一个简单的Java Web应用程序)创建。
注意:不能使用cocoon-22-archetype-webapp
注意:pom.xml引用service:
<dependencies>
<dependency>
<groupId>com.taotao</groupId>
<artifactId>taotao-manager-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
......
</dependencies>
taotao-manager-web的pom.xml为:
<?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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>taotao-manager</artifactId>
<groupId>com.taotao</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../taotao-manager/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>taotao-manager-web</artifactId>
<packaging>war</packaging>
<dependencies>
<!-- 单元测试 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>com.taotao</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>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- 文件上传组件 -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
</dependency>
</dependencies>
</project>
使用tomcat插件
我们使用maven的tomcat插件来运行项目,在此之前,确保在taotao-manager的pom文件中配置了tomcat的插件:
因为已经在taotao-parent中有配置了,所以在taotao-manager-web中没有此配置了。
<build>
<!-- 配置插件 -->
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<port>8080</port>
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>
运行web项目
1. 在taotao-manage-web模块中随意改动index.jsp
2. 配置Maven Tomcat Plugin
3. 启动
启动成功情况:
访问成功
可能遇到的错误
1.Error:(20,21) java: 程序包javax.portlet不存在
错误所在文件:taotao-commonsrcmainjavacom.taotaoMyPortlet.java
解析:本文件是portlet模板自动创建的,实际不需要
解决方法:直接删除此文件。
2.The POM for com.taotao:taotao-common:jar:1.0-SNAPSHOT is missing, no dependenc
可能是taotao-parent或taotao-common没有安装到本地仓库,出现的错误是找不到taotao-common的jar包
解决方法:安装一下(若不行则把taotao-parent也安装一下)
3. Invalid packaging for parent POM
日志:
Invalid packaging for parent POM com.taotao:taotao-common:1.0-SNAPSHOT (D:projectstaotaotaotao-commonpom.xml), must be "pom" but is "jar" @ com.taotao:taotao-common:1.0-SNAPSHOT, D:projectstaotaotaotao-commonpom.xml, line 11, column 16
原因:将taotao-manage的父模块错设置成taotao-common了,应该是taotao-parent。只要是父模块,maven项目类型就必须是pom类型。
其他网址
idea搭建淘淘商城项目 - 简书
基于maven使用IDEA创建多模块项目-CSDN博客
最后
以上就是闪闪小松鼠为你收集整理的Idea项目--多模块项目(淘淘商城)目录结构工程目录—taotao父工程—taotao-parent通用工程—taotao-common开发工程—taotao-manager开发工程—taotao-manager的子模块Web子工程—taotao-manager-web运行web项目可能遇到的错误其他网址的全部内容,希望文章能够帮你解决Idea项目--多模块项目(淘淘商城)目录结构工程目录—taotao父工程—taotao-parent通用工程—taotao-common开发工程—taotao-manager开发工程—taotao-manager的子模块Web子工程—taotao-manager-web运行web项目可能遇到的错误其他网址所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复