我正在尝试构建一个使用spring boot运行的可执行jar,但是我无法将spring xml从resources文件夹中获取到jar中。看起来我的outputDirectory是错误的。定义它的正确方法是什么,它被打包在jar中?
这是我的pom文件
<build>
<resources>
<resource>
<directory>${basedir}/src/main/resources/my-resources</directory>
<includes>
<include>*xml</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>netexchange.exchange.main.ExchangeMain</mainClass>
</manifest>
</archive>
<outputDirectory>${basedir}/target</outputDirectory>
<finalName>Matcher-with-config</finalName>
<addResources>true</addResources>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<defaultGoal>install</defaultGoal>
<directory>${basedir}/target</directory>
</build>
答案 0 :(得分:0)
所以我想出了一个解决方案,即将特定资源复制到文件夹“src / main / resources”中。 Spring引导构建自动包含该文件夹中的所有文件,然后您可以使用注释“@ImportResource({”classpath:config.xml“})”
导入它们。我更新的pom看起来像这样:
<build>
<resources>
<resource>
<directory>${basedir}/src/main/resources/bitcoin-ethereum</directory>
<includes>
<include>*xml</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>compile</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/src/main/resources</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/resources/matcher</directory>
<includes>
<include>*xml</include>
</includes>
</resource>
<resource>
<directory>${basedir}/src/main/resources/common</directory>
<includes>
<include>*xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>netexchange.exchange.main.ExchangeMain</mainClass>
</manifest>
</archive>
<outputDirectory>${basedir}/target</outputDirectory>
<finalName>Matcher</finalName>
<addResources>true</addResources>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<defaultGoal>install</defaultGoal>
<directory>${basedir}/target</directory>
</build>