2017-08-24 43 views
1

是否有可能直接针对由于包目标而不是源创建的jar文件运行maven,特别是spring-boot:run目标?Maven spring-boot:针对编译的jar运行

我想这样做的原因是因为我想使用Spring引导Devtools在Docker容器中运行一个具有热插拔类(存储在主机上并映射到容器中使用共享卷)的Spring引导应用程序如果你使用Java -jar运行应用程序,可悲的是不起作用),我也不想将应用程序的源代码放在容器中。

回答

0

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启动插件催生了JVM是:(1)你的应用程序JAR和(2 )空的类目录。例如:

[DEBUG] Classpath for forked process: <full_path_removed>/tmp/lib/your-application.jar.original:/tmp: 

注:

  • 你需要,因为你使用的是原来的JAR不包括在META-INF/MANIFEST.MF主类指令提供mainClass
  • 您需要引用“原始”JAR而不是Spring Boot打包的JAR,因为原始JAR是包含应用程序的主类在其原始位置(Spring Boot打包的JAR重定位它)的JAR。
相关问题