2017-05-10 188 views
0

我在將我的spring引導應用程序部署到tomcat時遇到問題,雖然在我的IDE中運行良好。 我遵循https://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.htmlSpring引導應用程序 - Tomcat部署

的指示但結果我得到了一個只包含框架庫和web類的war包,沒有包含我的核心模塊。

我不確定我的pom文件是否正確。我的項目

結構看起來像:

portal 
    -web 
    -src 
    pom1.xml 
    -core 
    -src 
    pom2.xml 
pom0.xml 

項目POM(pom0.xml):

<modules> 
    <module>core</module> 
    <module>web</module> 
    <module>tests</module> 
</modules> 
<packaging>pom</packaging> 

<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.5.3.RELEASE</version> 
</parent> 

<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
    <java.version>1.8</java.version> 
</properties> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
     </plugin> 
    </plugins> 
</build> 

網絡模塊POM(pom1.xml):

<parent> 
    <artifactId>portal</artifactId> 
    <groupId>com.portal</groupId> 
    <version>0.0.1-SNAPSHOT</version> 
</parent> 
<modelVersion>4.0.0</modelVersion> 

<artifactId>web</artifactId> 
<packaging>war</packaging> 

<dependencies> 
    <dependency> 
     <groupId>com.portal</groupId> 
     <artifactId>core</artifactId> 
     <version>${project.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>io.springfox</groupId> 
     <artifactId>springfox-swagger2</artifactId> 
     <version>2.6.1</version> 
    </dependency> 

    <dependency> 
     <groupId>io.springfox</groupId> 
     <artifactId>springfox-swagger-ui</artifactId> 
     <version>2.6.1</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-test</artifactId> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-tomcat</artifactId> 
     <scope>provided</scope> 
    </dependency> 
</dependencies> 

核心模塊pom(pom2.xml)

<parent> 
    <artifactId>portal</artifactId> 
    <groupId>com.portal</groupId> 
    <version>0.0.1-SNAPSHOT</version> 
</parent> 
<modelVersion>4.0.0</modelVersion> 

<artifactId>core</artifactId> 

<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
    <java.version>1.8</java.version> 
</properties> 

<dependencies> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-data-rest</artifactId> 
    </dependency> 
    <dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-security</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>com.custom.api</groupId> 
     <artifactId>common-utils</artifactId> 
     <version>1.1</version> 
    </dependency> 
</dependencies> 

UPDATE1

更詳細的結構:

-web 
    -com.portal.web 
    -controller 
    IncidentController 
    ComputerController 
    ... 
-core 
-com.portal.core 
    -domain 
    Incident 
    Computer 
    ... 

MVN清楚包給出錯誤:

[INFO] portal ............................................. SUCCESS [ 0.700 s] 
[INFO] core ............................................... SUCCESS [ 2.478 s] 
[INFO] web ................................................ FAILURE [ 0.458 s] 
[INFO] tests .............................................. SKIPPED 
... 
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project web: Compilation failure: Compilation failure: 
[ERROR] /.../portal/web/src/main/java/com/portal/web/controller/IncidentController.java:[4,37] package com.portal.core.domain does not exist 
[ERROR] /.../portal/web/src/main/java/com/portal/web/controller/IncidentController.java:[5,38] package com.portal.core.service does not exist 
[ERROR] /.../portal/web/src/main/java/com/portal/web/controller/IncidentController.java:[18,19] cannot find symbol 
[ERROR] symbol: class IIncidentService 
[ERROR] location: class com.portal.web.controller.IncidentController 
... 

回答

0

多模塊項目的解決方案是配置引導的重新包裝的分類應用到罐子:

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
      <executions> 
       <execution> 
        <goals> 
         <goal>repackage</goal> 
        </goals> 
        <configuration> 
         <classifier>exec</classifier> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

問題進行全面介紹here

0

添加 「網絡模塊」 到母體中的模塊部「門戶模塊「:

<modules> 
    <module>core</module> 
    <module>api</module> 
    <module>tests</module> 
    <module>web</module> 
</modules> 

在父「門戶模塊」的文件夾中運行mvn clean package

+0

感謝您的回答。這是一個錯字,模塊web存在於父文件夾的模塊中。我更新了執行mvn clean package後得到的錯誤。 – Mark

相關問題