如何在从 Maven 运行的 Spring Boot 中添加额外的类路径条目?
我想我需要在我的 pom.xml 中添加这样的东西:
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>C:/resources</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
Run Code Online (Sandbox Code Playgroud)
但是,我不知道什么插件适用。
我假设您想要的是将额外的资源/配置文件添加到 Spring Boot 生成的可执行 jar 中的类路径中。我发现的唯一现成解决方案是使用maven-jar-plugin除了spring-boot-maven-plugin将类路径添加到清单中,例如:
<!-- setup jar manifest to executable with dependencies -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.3.RELEASE</version>
<configuration>
<fork>true</fork>
<mainClass>Application</mainClass>
<classifier>executable</classifier>
<layout>JAR</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- add configuration to manifest -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifestEntries>
<Class-Path>conf/</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
请注意,类路径将相对于生成的可执行 JAR 文件。
oot*_*ero -3
不会:
java -cp <path to classpath entry> -jar <path to program.jar>
Run Code Online (Sandbox Code Playgroud)
为你工作?
| 归档时间: |
|
| 查看次数: |
2347 次 |
| 最近记录: |