2017-06-14 64 views
0

基本上,我有一個多模塊項目如下:不能在一個多模塊項目妥善包裝春天啓動應用程序

parent-project 
├── core-app 
└── web-app 

core-appweb-app都是春天啓動的項目,他們的父母是parent-project而不是spring-boot-starter-parent。所以,正因如此,它們都具有:

<dependencyManagement> 
     <dependencies> 
      <dependency> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-dependencies</artifactId> 
       <type>pom</type> 
       <version>${spring.boot.version}</version> 
       <scope>import</scope> 
      </dependency> 
     </dependencies> 
    </dependencyManagement> 

在他們pom.xml,以及:

<plugin> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-maven-plugin</artifactId> 
    <version>${spring.boot.version}</version> 
    <configuration> 
     <executable>true</executable> 
    </configuration> 
</plugin> 

這樣的設置完全內的IntelliJ運行,但是,如果我package的應用程序,我得到一個非常小.jar和基本上如果我試圖運行它可執行文件,我得到幾個command not found錯誤。

如果我用java -cp my.jar com.Main運行它,我得到SpringApplication not found。所以從這裏我知道core-appweb-app沒有jar中的所有依賴關係。

如果我將它構建爲以spring-boot-starter-parent作爲其父項的獨立.jar;有用。

我在做什麼錯?謝謝。

更新:

現在這是發生了什麼事,當我mvn package。然而,當我實際執行mvn spring-boot:repackage我越來越:

Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:1.5.2.RELEASE:repackage failed: Source must refer to an existing file 

由於這裏建議this似乎解決了問題,但我懷疑這可能不是標準的方式。例如:

mvn clean package spring-boot:repackage訣竅,但是,我不能mvn clean && mvn package && mvn spring-boot:repackage。我希望對此有所解釋。謝謝!

+0

只是一個想法 - 當您已經將產品作爲微服務運輸時,需要多模塊項目嗎? –

+0

我需要將域對象/ POJO分離到一個模塊中,以便非技術人員在完全不同的應用程序中使用它們。 –

+1

您應該使用'java -jar my.jar'而不是'java -cp my.jar com.Main'運行。 –

回答

1

Maven項目只能有一個父項,而您的「模塊」不能是模塊,除非parent-project是父項。您理論上可以讓project-parent擴展Boot父項,但這可能會很匆忙地變得複雜。

相反,只需繼續並選擇性地使用引導依賴關係和包含。使用dependencyManagement和BOM導入在parent-project,拉實際上只需要爲每個模塊(可能包括spring-boot-starter-web爲你的脂肪JAR)的依賴,並添加Maven插件爲獨立遠罐子模塊僅

<plugin> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-maven-plugin</artifactId> 
    <executions> 
     <execution> 
      <goals> 
       <goal>repackage</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 

然後你會得到標準大小(通常是幾K)的依賴瓶和整個處理,特別是在需要的地方。

+0

這實際上正是我所做的(我已經在'dependencyManagement'父pom和子模塊'pom中嘗試了Boot的依賴關係),並且仍然出現錯誤。 –

+0

@HananCanSaral你的代碼片段不包含「重新包裝」目標,這是在最後創建脂肪罐的部分。 – chrylis

+0

它實際上,它不知道發佈。但我相信,即使有「目標」,重新打包目標也不會被調用,請參閱上述更新。感謝您的幫助,謝謝! –

相關問題