1、首先先把配置文件从jar中抽离
示例代码:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<excludes>
<exclude>**/spring-paytrade-front-jsf.xml</exclude>
</excludes>
</configuration>
</plugin>
2、把抽离的配置文件,放到conf目录下
利用maven-assembly-plugin,抽取配置文件到conf目录下,
示例代码:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
assembly.xml内容如下:
<assembly>
<id>assembly</id>
<formats>
<format>zip</format>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${basedir}/src/bin</directory>
<outputDirectory>bin</outputDirectory>
<fileMode>0755</fileMode>
</fileSet>
</fileSets>
<files>
<file>
<source>${project.build.directory}/${project.build.finalName}.jar</source>
<outputDirectory>lib</outputDirectory>
</file>
<file>
<source>${basedir}/../hachi-cashier-paytool/hachi-cashier-paytool-acl-adapters/target/classes/spring/spring-paytrade-front-jsf.xml</source>
<outputDirectory>conf</outputDirectory>
</file>
<file>
<source>${basedir}/../hachi-cashier-paytool/hachi-cashier-paytool-ohs-remote/target/classes/spring/spring-paytrade-front-jsf-provider.xml</source>
<outputDirectory>conf</outputDirectory>
</file>
</files>
</assembly>
最终效果如下:
3、修改maven打包配置将conf加入到classpath中
示例代码如下:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifestEntries>
<Class-Path>../conf/</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
最终达到的效果是:
将springboot的jar包解压后,可以看到.MF文件中加了一个类路径 ../conf
特别注意:
java -jar XX
使用-jar启动java进程的,-classpath不会生效了,如果要加类路径,只能通过改maven的打包参数,从而使得.MF文件加了Class-Path属性后,才可以!!!!
4、到j-one上新建conf文件夹,将要覆盖的配置文件加入进去
示例:
5、测试是否生效
修改了jsf的别名为:payChannel_hachi_pre_m6
代码里的别名是payChannel_hachi_pre
如下:http 和 jsf 服务都正常启动