基于命令行执行jar的外放配置文件的执行方法

基于命令行执行jar的外放配置文件的执行方法
配置文件在工程目录存放位置:

src/conf/application.properties

打包生成sproutgis-exec.jar文件
拷贝到/usr/test目录下,目录内容:

#---------------------------------------
conf/application.properties
lib/*.jar          #存放的项目依赖库
sproutgis-exec.jar
execute_jar.sh
#---------------------------------------

execute_jar.sh文件内容为:
分隔符问题:linux中jar与lib用冒号":",window中jar与lib用分号";"

#!/bin/bash
java -cp sproutgis-exec.jar:lib/*:./conf com.sapsoft.controller.app

项目依赖库lib 生成方法:
在项目根目录里执行以下dos命令,会自动生成一个lib目录,里面是生成的依赖库*.jar:

mvn dependency:copy-dependencies  -DoutputDirectory=lib

pom.xml打包配置内容:

<plugin>
                    <artifactId>maven-jar-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>exec</id>
                            <phase>package</phase>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                            <configuration>
                                <classifier>exec</classifier>
                                <archive>
                                    <manifest>
                                        <mainClass>com.sapsoft.controller.app</mainClass>
                                        <addClasspath>true</addClasspath><!-- 添加依赖jar路径 -->
                                        <classpathPrefix>lib/</classpathPrefix>
                                    </manifest>
                                </archive>
                            </configuration>
                        </execution>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                            <configuration>
                                <!-- Need this to ensure application.properties is excluded -->
                                <forceCreation>true</forceCreation>
                                <excludes>
                                    <exclude>conf/application.properties</exclude>
                                </excludes>
                                <archive>
                                    <manifest>
                                        <mainClass>com.sapsoft.controller.app</mainClass>
                                        <addClasspath>true</addClasspath><!-- 添加依赖jar路径 -->
                                        <classpathPrefix>lib/</classpathPrefix>
                                    </manifest>
                                </archive>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

参考地址:
https://blog.csdn.net/xrq0508/article/details/80050119

猜你喜欢

转载自blog.csdn.net/hsg77/article/details/85762530
今日推荐