繁体   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