springBoot聚合项目打包

转载自:https://blog.csdn.net/qq_28929589/article/details/79267467

项目结构

core不依赖谁

user依赖core

hr依赖user和core

hr是主模块,application的入口放在这里的

如果以后我在做一个项目比如hr1,我可以再次去依赖core和user。

core和user。就可以公用了。。。。

其次我的pom.xml的父文件

 

<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>
     <packaging>pom</packaging>
     <!-- 项目说明:这里作为聚合工程的父工程 -->
     <groupId>com.ewe</groupId>
     <artifactId>ewe-hr</artifactId>
     <version>1.0.0.RELEASE</version>
     
      <!-- 继承说明:这里继承SpringBoot提供的父工程 -->
     <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
     </parent>
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.7</java.version>
    </properties>
     <!-- 模块说明:这里声明多个子模块 -->
     <modules>
        <module>core</module>
        <module>hr</module>
        <module>user</module>
     </modules>
     <dependencyManagement>
      <!-- 模块说明:这里声明多个子模块 -->
          <dependencies>
             <!--子版本依赖-->
            <dependency>
                <groupId>com.ewe</groupId>
                <artifactId>core</artifactId>
                <version>0.0.1-SNAPSHOT</version>
            </dependency>  
            <dependency>
                <groupId>com.ewe</groupId>
                <artifactId>user</artifactId>
                <version>0.0.1-SNAPSHOT</version>
            </dependency>
            <dependency>
                <groupId>com.ewe</groupId>
                <artifactId>hr</artifactId>
                <version>0.0.1-SNAPSHOT</version>
            </dependency>
        </dependencies>
     </dependencyManagement>
</project>

 

切记父文件不需要打包。
不需要写 

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

 

再次我的core文件

<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>
     <packaging>pom</packaging>
     <!-- 项目说明:这里作为聚合工程的父工程 -->
     <groupId>com.ewe</groupId>
     <artifactId>ewe-hr</artifactId>
     <version>1.0.0.RELEASE</version>
     
      <!-- 继承说明:这里继承SpringBoot提供的父工程 -->
     <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
     </parent>
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.7</java.version>
    </properties>
     <!-- 模块说明:这里声明多个子模块 -->
     <modules>
        <module>core</module>
        <module>hr</module>
        <module>user</module>
     </modules>
     <dependencyManagement>
      <!-- 模块说明:这里声明多个子模块 -->
          <dependencies>
             <!--子版本依赖-->
            <dependency>
                <groupId>com.ewe</groupId>
                <artifactId>core</artifactId>
                <version>0.0.1-SNAPSHOT</version>
            </dependency>  
            <dependency>
                <groupId>com.ewe</groupId>
                <artifactId>user</artifactId>
                <version>0.0.1-SNAPSHOT</version>
            </dependency>
            <dependency>
                <groupId>com.ewe</groupId>
                <artifactId>hr</artifactId>
                <version>0.0.1-SNAPSHOT</version>
            </dependency>
        </dependencies>
     </dependencyManagement>
</project>

 

我的core文件不需要打包,因为我的主项目hr需要core包中的依赖,打包了就找不到了

 

然后我的user文件

 

<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.ewe</groupId>
    <artifactId>ewe-hr</artifactId>
    <version>1.0.0.RELEASE</version>
     <relativePath>../pom.xml</relativePath>
  </parent>
  <artifactId>user</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>user</name>
  <description>user information</description>
  <dependencies>
      <dependency>
          <groupId>com.ewe</groupId>
          <artifactId>core</artifactId>
      </dependency>  
      
  </dependencies>
 <!-- Package as an executable jar -->
    <build>
          <resources>
           <resource>
               <directory>src/main/java</directory>
               <includes>
                   <include>**/*.xml</include>
               </includes>
           </resource>
           <resource>
               <directory>src/main/resources</directory>
               <includes>
                   <include>**.*</include>
                   <include>**/*.*</include><!-- i18n能读取到 -->
                    <include>**/*/*.*</include>
               </includes>
           </resource>
         </resources>
    </build>
</project>

 

为什么user有build呢,因为依赖的打包的时候我只是指明了需要打包的目录resources

 

最后我的住主项目hr

<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>
  <artifactId>hr</artifactId>
  <name>hr</name>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
  
   <!-- 继承本项目的父工程 -->
    <parent>
        <groupId>com.ewe</groupId>
        <artifactId>ewe-hr</artifactId>
        <version>1.0.0.RELEASE</version>
        <relativePath>../pom.xml</relativePath>
    </parent>
      <dependencies>
      <dependency>
          <groupId>com.ewe</groupId>
          <artifactId>core</artifactId>
      </dependency>  
      <dependency>
          <groupId>com.ewe</groupId>
          <artifactId>user</artifactId>
      </dependency>  
      </dependencies>
     <!-- Package as an executable jar -->
    <build>
          <resources>
           <resource>
               <directory>src/main/java</directory>
               <includes>
                   <include>**/*.xml</include>
               </includes>
           </resource>
           <resource>
               <directory>src/main/resources</directory>
               <includes>
                   <include>**.*</include>
                   <include>**/*.*</include><!-- i18n能读取到 -->
                    <include>**/*/*.*</include>
               </includes>
           </resource>
         </resources>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
           
            <configuration>
                 <fork>true</fork> <!-- 如果没有该配置,devtools不会生效 -->
                <!-- 指定该Main Class为全局的唯一入口 -->
                <mainClass>com.ewe.Application</mainClass>
                <layout>ZIP</layout>
          </configuration>
          <executions>
            <execution>
              <goals>
                <goal>repackage</goal><!--可以把依赖的包都打包到生成的Jar包中-->
              </goals>
            </execution>
          </executions>
          </plugin>
        </plugins>
        <finalName>hr</finalName>
    </build>
</project>

 

需要进行打包并指明main函数的入口

 
posted @ 2018-08-11 23:57  小手星的矮子  阅读(4852)  评论(0编辑  收藏  举报