[英]How to package spring-boot to jar with local jar using maven
[英]Maven spring-boot:run against compiled jar
是否可以直接针对由于打包目标而不是源代码创建的jar文件运行maven,尤其是spring-boot:run目标?
我想要这样做的原因是因为我想使用Spring Boot Devtools在Docker容器中运行具有热插拔类的spring boot应用程序(可存储在主机上,并使用共享卷映射到容器中),但遗憾的是没有如果您使用Java -jar运行应用程序,则可以正常工作,而我也不想将应用程序的源代码放入容器中。
classes
参数不是可选的(通常使用标准的Maven项目结构来推断),但是可以为它提供一个空目录,然后使用folders
参数包含以前打包的JAR。 这是一个例子
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.this.that.YourApplication</mainClass>
<!-- any directory will do as long as (a) it exists and (b) it does not contain classes -->
<classesDirectory>/tmp/</classesDirectory>
<folders>
<folder>
<!-- the address, relative to the plugin's workingDirectory, of the 'original' application JAR -->
tmp/lib/your-application.jar.original
</folder>
</folders>
</configuration>
</plugin>
使用此配置,如果使用-X
运行,您将看到由Spring Boot插件生成的JVM的类路径中的前两个条目是(1)您的应用程序JAR和(2)空的classes目录。 例如:
[DEBUG] Classpath for forked process: <full_path_removed>/tmp/lib/your-application.jar.original:/tmp:
笔记:
mainClass
因为您使用的是原始JAR,该JAR在META-INF / MANIFEST.MF中不包含Main-Class指令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.