方法1. 使用mvn插件打包(推荐)

pom代码

    <build>
        <plugins&gt;

            <plugin&gt;
                <groupId&gt;org.apache.maven.plugins</groupId&gt;
                <artifactId&gt;maven-surefire-plugin</artifactId&gt;
                <version&gt;2.22.2</version&gt;
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>

            <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>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>


            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                    <mainClass>com.iristar.TestApplication</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <id>repackage</id>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>
    <!--    springboot自带build end-->

启动脚本
set path=%PATH%;dll
java -jar ./target/evalserver-1.0-SNAPSHOT.jar spring.config.addition-location=./application.properties 
    
#!/bin/bash
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./dll java -jar ./target/evalserver-1.0-SNAPSHOT.jar spring.config.addition-location=./application.properties 

方法2. 使用 idea的Artifacts打包

clipboard.png

clipboard.png

clipboard.png

clipboard.png

clipboard.png


方法3. 使用package打包

pom代码

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <!-- spring-boot:run 中文乱码解决 -->
                    <jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
                    <mainClass>com.iristar.center.ht.ApiServer</mainClass>
                    <!-- 生成脚本文件名称比如start.sh,你也可以根据你的需要命名成其他名字 -->
                </configuration>
            </plugin>
            <!--打包时跳过测试-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>
            <!--打包部署插件-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>utf8</encoding>
                    <compilerArgs>
                        <arg>-XDignore.symbol.file</arg>
                    </compilerArgs>
                    <fork>true</fork>

                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>appassembler-maven-plugin</artifactId>
                <version>2.0.0</version>
                <executions>
                    <execution>
                        <id>Make Assembly</id>
                        <!-- 绑定package生命周期阶段上 -->
                        <phase>package</phase>
                        <goals>
                            <goal>assemble</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <!-- 生成linux, windows两种平台执行脚本 -->
                    <platforms>
                        <platform>unix</platform>
                        <platform>windows</platform>
                    </platforms>
                    <!-- 包存放根目录 -->
                    <assembleDirectory>${project.build.directory}/product</assembleDirectory>
                    <!-- 打包的jar,以及maven依赖jar存放目录 -->
                    <repositoryName>lib</repositoryName>
                    <!-- lib目录jar的存放规则默认是${groupId}/${artifactId}的目录格式flat表示直接jar放到lib目录 -->
                    <!-- 可执行脚本的存放目录 -->
                    <binFolder>bin</binFolder>
                    <!-- 配置文件的存放目录 -->
                    <configurationDirectory>conf</configurationDirectory>
                    <!-- 拷贝配置文件到上面的目录中 -->
                    <copyConfigurationDirectory>true</copyConfigurationDirectory>
                    <!-- 从哪里拷贝配置文件 (默认src/main/config) -->
                    <configurationSourceDirectory>src/main/resources</configurationSourceDirectory>
                    <repositoryLayout>flat</repositoryLayout>
                    <encoding>UTF-8</encoding>
                    <logsDirectory>logs</logsDirectory>
                    <tempDirectory>tmp</tempDirectory>
                    <programs>
                        <program>
                            <!-- 启动类 -->
                            <mainClass>com.iristar.center.ht.ApiServer</mainClass>
                            <!-- 生成脚本文件名称比如start.sh,你也可以根据你的需要命名成其他名字 -->
                            <name>ApiServer</name>
                            <jvmSettings>
                                <extraArguments>
                                    <extraArgument>-server</extraArgument>
                                    <extraArgument>-Xmx2G</extraArgument>
                                    <extraArgument>-Xms2G</extraArgument>
                                    <extraArgument>-Dfile.encoding=UTF-8</extraArgument>
                                </extraArguments>
                            </jvmSettings>
                        </program>
                    </programs>
                </configuration>
            </plugin>
            <!--打包部署插件-->
        </plugins>

        <!--<resources>-->
        <!--<resource>-->
        <!--<directory>{project.basedir}/lib</directory>-->
        <!--<targetPath>${project.build.directory}/product/lib</targetPath>-->
        <!--<includes>-->
        <!--<include>**/*</include>-->
        <!--</includes>-->
        <!--</resource>-->
        <!--</resources>-->

        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.properties</include>
                    <include>**/*.yml</include>
                </includes>
                <filtering>false</filtering>
            </resource>

            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.*</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
    </build>

命令如下
mvn clean package appassembler:assemble

clipboard.png

注意事项
问题(1):

windows提示输入行太长
解决方法:
将原来的引入包的地方全部删掉改为*
110171004972.png

问题(2):

windows提示找不到动态
解决方法:
setx -m PATH “%PATH%;./”

linux提示找不到动态
解决方法:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./

原文地址:https://blog.csdn.net/weixin_39310549/article/details/129092186

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_43248.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注