maven打可执行的jar包,将配置文件打到外面。pom.xml里面的配置

配置如下:    

    打包后的结果为:target----etc目录下面有lib文件,properties文件,xml日志文件。

    还有一个jar包,将jar包放在etc目录下,就正确可以执行jar包了。


<build>
    <resources>
        <!--指定src/main/resources资源要过滤-->
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
    <plugins>
        <!-- 可执行jar插件 -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                        <mainClass>ssp.lanxinpay.settlement.MainApp</mainClass>
                    </manifest>
                    <manifestEntries>
                        <Class-Path>.</Class-Path>
                    </manifestEntries>
                </archive>
                <excludes>
                    <exclude>**/*.xml</exclude>
                    <exclude>**/*.conf</exclude>
                    <exclude>**/*.properties</exclude>
                </excludes>

            </configuration>
        </plugin>
        <!-- maven资源文件复制插件 -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.7</version>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <!-- here the phase you need -->
                    <phase>package</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/etc</outputDirectory>
                        <resources>
                            <resource>
                                <directory>src/main/resources</directory>
                                <includes>
                                    <exclude>**/*.xml</exclude>
                                    <exclude>**/*.conf</exclude>
                                    <exclude>**/*.properties</exclude>
                                </includes>
                                <filtering>true</filtering>
                            </resource>
                        </resources>
                        <encoding>UTF-8</encoding>
                    </configuration>
                </execution>
            </executions>
        </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}/etc/lib</outputDirectory>
                        <!-- 是否不包含间接依赖 -->
                        <excludeTransitive>false</excludeTransitive>
                        <!-- 忽略版本 -->
                        <stripVersion>false</stripVersion>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.18.1</version>
            <configuration>
                <skipTests>true</skipTests>
            </configuration>
        </plugin>
    </plugins>
</build>

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
Maven 是一个基于项目对象模型(POM)的项目管理工具,可以通过配置 POM 文件来管理项目的构建、依赖、测试等等。 在 POM 文件中,可以通过配置 `<packaging>` 元素来指定项目打包的方式。常见的打包方式有 jar、war、ear 等。 例如,以下是一个打包方式为 jar 的 POM 配置: ```xml <project> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>my-project</artifactId> <version>1.0.0</version> <packaging>jar</packaging> ... </project> ``` 在执行 Maven 打包命令时,Maven 会根据 POM 文件中的配置来生成相应的打包文件。例如,执行以下命令可以生成一个名为 `my-project-1.0.0.jar` 的 jar 包: ``` mvn package ``` 同时,你也可以通过配置 `<build>` 元素来指定打包过程中的一些自定义操作,比如编译、测试、打包等等。例如: ```xml <project> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>my-project</artifactId> <version>1.0.0</version> <packaging>jar</packaging> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build> ... </project> ``` 以上配置中,使用了 Maven Compiler Plugin 插件,指定了编译时使用的 Java 版本为 1.8。 希望这些信息能够对你有所帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值