• 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>
    
  • 相关阅读:
    让一个 csproj 项目指定多个开发框架
    推荐近乎免费的调试神器——OzCode
    再也不用克隆多个仓库啦!git worktree 一个 git 仓库可以连接多个工作目录
    .NET Core 和 .NET Framework 中的 MEF2
    将 WPF、UWP 以及其他各种类型的旧样式的 csproj 文件迁移成新样式的 csproj 文件
    .NET 中的轻量级线程安全
    卡诺模型(KANO Model)
    C#/.NET 匿名函数会捕获变量,并延长对象的生命周期
    迫不及待地体验了一把 C#8.0 中的可空引用类型(Nullable Reference)
    异步任务中的重新进入(Reentrancy)
  • 原文地址:https://www.cnblogs.com/CSunShine/p/16375262.html
Copyright © 2020-2023  润新知