2017-08-24 36 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。
相關問題