[英]Maven spring-boot:run against compiled jar
Is it possible to run maven, and specifically the spring-boot:run goal, directly against the jar file created as a result of the package goal as opposed to the source? 是否可以直接针对由于打包目标而不是源代码创建的jar文件运行maven,尤其是spring-boot:run目标?
The reason I want to do this is because I want to run a spring boot app in a Docker container with hot swappable classes (stored on the host and mapped into the container using a shared volume) using spring boot Devtools (which sadly doesn't work if you run the application using Java -jar) and I don't want to put the source code for the app inside the container as well. 我想要这样做的原因是因为我想使用Spring Boot Devtools在Docker容器中运行具有热插拔类的spring boot应用程序(可存储在主机上,并使用共享卷映射到容器中),但遗憾的是没有如果您使用Java -jar运行应用程序,则可以正常工作,而我也不想将应用程序的源代码放入容器中。
The classes
parameter is not optional (it is typically inferred using the standard Maven project structure) but you could provide it with an empty directory and then include the previously packaged JAR using the folders
parameter. classes
参数不是可选的(通常使用标准的Maven项目结构来推断),但是可以为它提供一个空目录,然后使用folders
参数包含以前打包的JAR。 Here's an example 这是一个例子
<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>
With this configuration, if you run with -X
you'll see that the first two entries in the classpath for the JVM spawned by the Spring Boot plugin are (1) your application JAR and (2) the empty classes directory. 使用此配置,如果使用
-X
运行,您将看到由Spring Boot插件生成的JVM的类路径中的前两个条目是(1)您的应用程序JAR和(2)空的classes目录。 For example: 例如:
[DEBUG] Classpath for forked process: <full_path_removed>/tmp/lib/your-application.jar.original:/tmp:
Notes: 笔记:
mainClass
because you are using the original JAR which does not include the Main-Class instruction in META-INF/MANIFEST.MF mainClass
因为您使用的是原始JAR,该JAR在META-INF / MANIFEST.MF中不包含Main-Class指令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.