• Maven配置模板:资源分离打包


    完整Demo,直接复制build即可食用

    <?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>auto-test</artifactId>
            <groupId>com.test</groupId>
            <version>1.0-SNAPSHOT</version>
        </parent>
        <modelVersion>4.0.0</modelVersion>
    
        <artifactId>auto-perf-agent</artifactId>
    
        <properties>
            <maven.compiler.source>8</maven.compiler.source>
            <maven.compiler.target>8</maven.compiler.target>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>com.test</groupId>
                <artifactId>auto-test-common</artifactId>
                <version>1.0-SNAPSHOT</version>
            </dependency>
        </dependencies>
    
        <build>
            <finalName>${artifactId}</finalName>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <configuration>
    
                        <!-- 根据情况,排除文件配置 -->
                        <!-- <excludes> -->
                        <!-- <exclude>*.**</exclude> -->
                        <!-- <exclude>*/**.xml</exclude> -->
                        <!-- </excludes> -->
    
                        <!-- 包含文件配置,配置只打包 com 文件夹 -->
                        <includes>
                            <include>
                                **/com/**
                            </include>
                        </includes>
    
                        <archive>
                            <manifest>
                                <!-- 配置加入依赖包:MANIFEST.MF -->
                                <addClasspath>true</addClasspath>
                                <!-- 前缀,写在MANIFEST.MF文件中 -->
                                <classpathPrefix>lib/</classpathPrefix>
                                <useUniqueVersions>false</useUniqueVersions>
                                <!-- Spring Boot 启动类(自行修改) -->
                                <mainClass>com.test.PerfTestAgentApplication</mainClass>
                            </manifest>
                            <manifestEntries>
                                <!-- 外部资源路径加入 MANIFEST.MF 的 Class-Path -->
                                <!-- 写多个 Class-Path 貌似只有最后一个才能生效,可以写在同一行,空格隔开 -->
                                <Class-Path>resources/</Class-Path>
                            </manifestEntries>
                        </archive>
                        <!-- jar 输出目录 -->
                        <outputDirectory>${project.build.directory}/pkgs/</outputDirectory>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <!-- 复制依赖 -->
                    <executions>
                        <execution>
                            <id>copy-dependencies</id>
                            <phase>package</phase>
                            <goals>
                                <goal>copy-dependencies</goal>
                            </goals>
                            <configuration>
                                <!-- 依赖包 输出目录 -->
                                <outputDirectory>${project.build.directory}/pkgs/lib</outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <executions>
                        <!-- 复制资源到resources目录 -->
                        <execution>
                            <id>copy-resources</id>
                            <phase>package</phase>
                            <goals>
                                <goal>copy-resources</goal>
                            </goals>
                            <configuration>
                                <resources>
                                    <resource>
                                        <directory>src/main/resources</directory>
                                        <excludes>
                                            <exclude>**/*.sh</exclude>
                                        </excludes>
                                    </resource>
                                </resources>
                                <!-- 资源文件 输出目录 -->
                                <outputDirectory>${project.build.directory}/pkgs/resources</outputDirectory>
                            </configuration>
                        </execution>
                        <!-- 复制shell脚本到根目录 -->
                        <execution>
                            <id>copy-resources-shell</id>
                            <phase>package</phase>
                            <goals>
                                <goal>copy-resources</goal>
                            </goals>
                            <configuration>
                                <resources>
                                    <resource>
                                        <directory>src/main/resources</directory>
                                        <includes>
                                            <include>**/*.sh</include>
                                        </includes>
                                    </resource>
                                </resources>
                                <!-- 资源文件 输出目录 -->
                                <outputDirectory>${project.build.directory}/pkgs</outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </project>
    
  • 相关阅读:
    大话设计模式笔记 装饰模式
    大话设计模式笔记 依赖倒转原则
    大话设计模式笔记 单一职责原则 开放-封闭原则
    Effective Java 英文 第二版 读书笔记 Item 5:Avoid creating unnecessary objects.
    Effective Java 英文 第二版 读书笔记 Item 4:Attempting to enforce noninstantiability by making a class abstract does not work.
    Effective Java 英文 第二版 读书笔记 Item 3:Enforce the singleton property with a private constructor or an enum type.
    Effective Java 英文 第二版 读书笔记 Item 2:Consider a builder when faced with many constructor parameters.
    大话设计模式笔记 策略模式
    大话设计模式笔记 简单工厂模式
    jvm的垃圾回收算法
  • 原文地址:https://www.cnblogs.com/CSunShine/p/16375262.html
Copyright © 2020-2023  润新知