• (03)maven项目分模块开发,子项目继承自父项目,打包运行方法


      现在有一个项目结构如下:

      父项目project

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.xxx.xxx</groupId> <artifactId>project</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>pom</packaging> <dependencyManagement> <dependencies> <dependency> <groupId>io.spring.platform</groupId> <artifactId>platform-bom</artifactId> <version>Brussels-SR4</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <modules> <module>../projectA</module> <module>../projectB</module> <module>../projectC</module> </modules>

      子项目projectA继承自父项目project

    <modelVersion>4.0.0</modelVersion>
    
    <artifactId>projectA</artifactId>
    <parent>
        <groupId>com.xxx.xxx</groupId>
        <artifactId>project</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <relativePath>../project</relativePath>
    </parent> 
      
    <dependencies>
        ... ...
    </dependencies>

      子项目projectB继承自父项目project,同时引入了projectA做为依赖

    <modelVersion>4.0.0</modelVersion>
    
    <artifactId>projectB</artifactId>
    <parent>
        <groupId>com.xxx.xxx</groupId>
        <artifactId>project</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <relativePath>../project</relativePath>
    </parent> 
      
    <dependencies>
        <dependency> 
            <groupId>com.xxx.xxx</groupId>
            <artifactId>projectA</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </dependency>
        ... ...
    </dependencies>        

      子项目projectC继承自父项目project,同时引入了projectB做为依赖

    <modelVersion>4.0.0</modelVersion>
    
    <artifactId>projectC</artifactId>
    <parent>
        <groupId>com.xxx.xxx</groupId>
        <artifactId>project</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <relativePath>../project</relativePath>
    </parent> 
      
    <dependencies>
        <dependency> 
            <groupId>com.xxx.xxx</groupId>
            <artifactId>projectB</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </dependency>
        ... ...
    </dependencies>   

      现在要打包,直接在project上执行clean compile package打出的包无法运行,需要修改projectC(客户写的源码)的pom.xml文件

    ... ...
    </dependencies>
    
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>1.3.3.RELEASE</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <finalName>demo</finalName>
    </build>        

      然后在project上执行上述命令,打出的jar名字是demo.jar,运行:java -jar demo.jar即可

  • 相关阅读:
    如何使用Java计算货币/钱~(How to calculate monetary values in Java)
    BigDecimal类
    状态码定义
    常见服务器返回状态码(Status Codes)
    2020-3-26学习地图
    ReentrantLock类
    HashSet类
    Vector类
    课程总结
    第十四周课程总结&实验报告
  • 原文地址:https://www.cnblogs.com/javasl/p/12952008.html
Copyright © 2020-2023  润新知