新建maven父项目(用来管理jar包版本),使子系统使用同一个版本的jar包。

File-》New-》Other-》Maven Project,打包方式选pom

 

  1. <!-- 集中定义依赖版本号 -->
  2. <properties>
  3. <activemq.version>5.11.2</activemq.version>
  4. <freemarker.version>2.3.23</freemarker.version>
  5. <quartz.version>2.2.2</quartz.version>
  6. </properties>
  7. <!-- dependencyManagement管理包的版本,并没有添加依赖 -->
  8. <dependencyManagement>
  9. <dependencies>
  10. <!-- 时间操作组件 -->
  11. <dependency>
  12. <groupId>joda-time</groupId>
  13. <artifactId>joda-time</artifactId>
  14. <version>${joda-time.version}</version>
  15. </dependency>
  16. </dependencies>
  17. </dependencyManagement>
  18. <build>
  19. <finalName>${project.artifactId}</finalName>
  20. <plugins>
  21. <!-- 资源文件拷贝插件 -->
  22. <plugin>
  23. <groupId>org.apache.maven.plugins</groupId>
  24. <artifactId>maven-resources-plugin</artifactId>
  25. <version>2.7</version>
  26. <configuration>
  27. <encoding>UTF-8</encoding>
  28. </configuration>
  29. </plugin>
  30. <!-- java编译插件 -->
  31. <plugin>
  32. <groupId>org.apache.maven.plugins</groupId>
  33. <artifactId>maven-compiler-plugin</artifactId>
  34. <version>3.2</version>
  35. <configuration>
  36. <source>1.7</source>
  37. <target>1.7</target>
  38. <encoding>UTF-8</encoding>
  39. </configuration>
  40. </plugin>
  41. </plugins>
  42. <!-- 插件管理,此处并没有使用,子项目中build -->
  43. <pluginManagement>
  44. <plugins>
  45. <!-- 配置Tomcat插件 -->
  46. <plugin>
  47. <groupId>org.apache.tomcat.maven</groupId>
  48. <artifactId>tomcat7-maven-plugin</artifactId>
  49. <version>2.2</version>
  50. </plugin>
  51. </plugins>
  52. </pluginManagement>
  53. </build>

创建common通用工具类项目,父类为刚才创建的项目,打包方式为jar

  1. <parent>
  2. <groupId>cn.e3mall</groupId>
  3. <artifactId>e3-parent</artifactId>
  4. <version>0.0.1-SNAPSHOT</version>
  5. </parent>
  6. <groupId>cn.e3mall</groupId>
  7. <artifactId>e3-common</artifactId>
  8. <version>0.0.1-SNAPSHOT</version>
  9. <!-- 依赖的jar包 -->
  10. <dependencies>
  11. <!-- Jackson Json处理工具包 -->
  12. <dependency>
  13. <groupId>com.fasterxml.jackson.core</groupId>
  14. <artifactId>jackson-databind</artifactId>
  15. </dependency>
  16. <!-- httpclient -->
  17. <dependency>
  18. <groupId>org.apache.httpcomponents</groupId>
  19. <artifactId>httpclient</artifactId>
  20. </dependency>
  21. <!-- 单元测试 -->
  22. <dependency>
  23. <groupId>junit</groupId>
  24. <artifactId>junit</artifactId>
  25. <scope>test</scope>
  26. </dependency>
  27. <!-- 日志处理 -->
  28. <dependency>
  29. <groupId>org.slf4j</groupId>
  30. <artifactId>slf4j-log4j12</artifactId>
  31. </dependency>
  32. </dependencies>

创建聚合项目,聚合pojo、dao、interface、service等子项目。打包方式为pom,父项目为刚才创建的jar包版本管理项目。

  1. <parent>
  2. <groupId>cn.e3mall</groupId>
  3. <artifactId>e3-parent</artifactId>
  4. <version>0.0.1-SNAPSHOT</version>
  5. </parent>
  6. <groupId>cn.e3mall</groupId>
  7. <artifactId>e3-manager</artifactId>
  8. <version>0.0.1-SNAPSHOT</version>
  9. <packaging>pom</packaging>
  10.  
  11. <dependencies>
  12. <!--依赖e3-common通用工具类工程 -->
  13. <dependency>
  14. <groupId>cn.e3mall</groupId>
  15. <artifactId>e3-common</artifactId>
  16. <version>0.0.1-SNAPSHOT</version>
  17. </dependency>
  18. </dependencies>
  19.  
  20. <!-- e3-manager是聚合工程,聚合pojo、dao、service等子项目 -->
  21. <modules>
  22. <module>e3-manager-pojo</module>
  23. <module>e3-manager-dao</module>
  24. <module>e3-manager-interface</module>
  25. <module>e3-manager-service</module>
  26. <module>e3-manager-web</module>
  27. </modules>
  28. <!-- 配置tomcat插件 -->
  29. <build>
  30. <plugins>
  31. <plugin>
  32. <groupId>org.apache.tomcat.maven</groupId>
  33. <artifactId>tomcat7-maven-plugin</artifactId>
  34. <version>2.2</version>
  35. <configuration>
  36. <path>/</path> <!-- tomcat项目路径 -->
  37. <port>8080</port> <!-- tomcat端口 -->
  38. </configuration>
  39. </plugin>
  40. </plugins>
  41. </build>

右击步骤3创建的聚合项目,选择Maven Module,输入Module项目创建子项目,next选择jar打包方式,用相同的方法创建pojo、dao、interface、service、web(这个打包方式选择war)子项目。

 dao和interface依赖pojo,service依赖dao和interface,web依赖service。

 其中dao的pom文件为

  1. <dependencies>
  2. <dependency>
  3. <groupId>cn.e3mall</groupId>
  4. <artifactId>e3-manager-pojo</artifactId>
  5. <version>0.0.1-SNAPSHOT</version>
  6. </dependency>
  7. <!-- Mybatis -->
  8. <dependency>
  9. <groupId>org.mybatis</groupId>
  10. <artifactId>mybatis</artifactId>
  11. </dependency>
  12. <dependency>
  13. <groupId>org.mybatis</groupId>
  14. <artifactId>mybatis-spring</artifactId>
  15. </dependency>
  16. <dependency>
  17. <groupId>com.github.miemiedev</groupId>
  18. <artifactId>mybatis-paginator</artifactId>
  19. </dependency>
  20. <dependency>
  21. <groupId>com.github.pagehelper</groupId>
  22. <artifactId>pagehelper</artifactId>
  23. </dependency>
  24. <!-- MySql -->
  25. <dependency>
  26. <groupId>mysql</groupId>
  27. <artifactId>mysql-connector-java</artifactId>
  28. </dependency>
  29. <!-- 连接池 -->
  30. <dependency>
  31. <groupId>com.alibaba</groupId>
  32. <artifactId>druid</artifactId>
  33. </dependency>
  34. </dependencies>
  35. <!-- 如果不添加此节点mybatis的mapper.xml以及db.properties文件都会被漏掉。 -->
  36. <build>
  37. <resources>
  38. <resource>
  39. <directory>src/main/java</directory>
  40. <includes>
  41. <include>**/*.properties</include>
  42. <include>**/*.xml</include>
  43. </includes>
  44. <filtering>false</filtering>
  45. </resource>
  46. </resources>
  47. </build>

6.右击manager聚合项目Run as-》Maven build-》clean tomcat7:run

7.如果发现执行失败,且maven仓库中找不到父项目和common项目,此时需要右击这两个项目Run as-》Maven Install即可加载到本地仓库中。

8.执行成功,浏览器输入地址即可查看

 

版权声明:本文为aeolian原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/aeolian/p/8982473.html