簡體   English   中英

使用Jenkins將Spring Boot WAR部署到Tomcat

[英]Deploying Spring Boot WAR to Tomcat with Jenkins

我有一個Spring Boot Java應用程序,已經按照教程進行了設置,以便構建WAR。 我正在嘗試使用Jenkins將此WAR文件部署到遠程Tomcat 7服務器。 當我告訴Jenkins構建和部署應用程序時,Jenkins中的日志顯示一切都成功。 如果我登錄到承載Tomcat的遠程服務器,則可以看到WAR已復制到該服務器。 如果我查看日志文件,它將顯示以下內容:

INFO: Manager: list: Listing contexts for virtual host 'localhost'
Jun 03, 2016 10:17:10 PM org.apache.catalina.core.ApplicationContext log
INFO: Manager: undeploy: Undeploying web application at '/webapp'
Jun 03, 2016 10:17:11 PM org.apache.catalina.core.ApplicationContext log
INFO: Manager: deploy: Deploying web application '/webapp'
Jun 03, 2016 10:17:11 PM org.apache.catalina.core.ApplicationContext log
INFO: Manager: Uploading WAR file to /var/lib/tomcat7/webapps/webapp.war
Jun 03, 2016 10:17:19 PM org.apache.catalina.core.ApplicationContext log
INFO: 1 Spring WebApplicationInitializers detected on classpath

如果我轉到tomcat管理器應用程序,則表明webapp已部署並正在運行。 但是,如果我單擊指向上下文路徑的鏈接,則會得到一個404。我一生都無法弄清楚為什么它不起作用。

這是我的build.gradle文件,我正在運行bootRepackage命令來生成WAR:

buildscript {
    ext {
        springBootVersion = '1.3.5.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'

war {
    baseName = 'web'
    version = '1.0.1'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
}

configurations {
    providedRuntime
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web:1.3.3.RELEASE")
    compile('com.amazonaws:aws-java-sdk:+')
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('mysql:mysql-connector-java')
    compile('org.springframework.boot:spring-boot-starter-thymeleaf')
    providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.9'
}

所以我現在有點傻,但是問題是Jenkins是在Java 1.8中構建的,而服務器上的Tomcat是在Java 1.7中運行的。 我在/etc/default/tomcat7編輯了文件,並添加了“ JAVA_HOME =”。 重新啟動了Tomcat和voila,它像冠軍一樣工作。

有點令人沮喪,因為任何日志中都沒有任何內容表明這是一個問題。 即使返回404,一切都假裝正常工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM