项目拆分子工程(简单版)

拆分java-maven项目为子工程

1.将主工程的pom文件的Packaging 修改为pom,如:

2.(在主工程的pom)创建子工程service,如:

 

3.将原工程的代码逻辑以及pom信息迁移到discover_service或其他子工程(discover_client)中,如:

 

 注意:

主工程的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.wangzun</groupId>
  <artifactId>MyDiscovery</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
  <name>MyDiscovery</name>
    
  <properties>
    <!-- 公共的信息,比如一些dependency的版本号 -->
    <java.version>1.7</java.version>
  </properties>
  <!-- 一些公共的依赖 -->
  <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>1.4.6.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Camden.SR7</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
  <modules>
      <module>discover_service</module>
      <module>discover_client</module>
  </modules>
</project>

 

discover_service的pom:

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.wangzun</groupId>
    <artifactId>MyDiscovery</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>discover_service</artifactId>
  <name>discover_service</name>
  <url>http://maven.apache.org</url>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  
  <dependencies>
   <!--原工程需要的dependency-->
   <!--  <dependency></dependency> -->
  </dependencies>
</project>

 补充:注意修改主工程的信息时 需要同时修改子工程的信息,如:

把Artifact Id 修改为reop_discover

 

 子工程的pom中也要修改,如:

 

posted @ 2018-03-02 14:58  Johnson_wang  阅读(1737)  评论(0编辑  收藏  举报