简体   繁体   English

使用Jenkins将Spring Boot WAR部署到Tomcat

[英]Deploying Spring Boot WAR to Tomcat with Jenkins

I have a Spring Boot Java application that I have followed the tutorials to set up so that it builds a WAR. 我有一个Spring Boot Java应用程序,已经按照教程进行了设置,以便构建WAR。 I am attempting to deploy this WAR file using Jenkins, to a remote Tomcat 7 server. 我正在尝试使用Jenkins将此WAR文件部署到远程Tomcat 7服务器。 When I tell Jenkins to build and deploy the app the log in Jenkins shows that everything was successful. 当我告诉Jenkins构建和部署应用程序时,Jenkins中的日志显示一切都成功。 If I log into the remote server that is hosting Tomcat, I can see that the WAR was copied to the server. 如果我登录到承载Tomcat的远程服务器,则可以看到WAR已复制到该服务器。 If I look in the log files, it shows this: 如果我查看日志文件,它将显示以下内容:

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

If I go to the tomcat manager app, it shows that webapp is deployed and running. 如果我转到tomcat管理器应用程序,则表明webapp已部署并正在运行。 But if I click the link to the context path, I get a 404. I can't figure out for the life of me why this is not working. 但是,如果我单击指向上下文路径的链接,则会得到一个404。我一生都无法弄清楚为什么它不起作用。

This is my build.gradle file and I am running the bootRepackage command to generate the WAR: 这是我的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'
}

So I feel kind of dumb now, but the issue was Jenkins was building in Java 1.8 and Tomcat on my server was running in Java 1.7. 所以我现在有点傻,但是问题是Jenkins是在Java 1.8中构建的,而服务器上的Tomcat是在Java 1.7中运行的。 I edited the file at /etc/default/tomcat7 and added 'JAVA_HOME='. 我在/etc/default/tomcat7编辑了文件,并添加了“ JAVA_HOME =”。 Restarted Tomcat and voila, it worked like a champ. 重新启动了Tomcat和voila,它像冠军一样工作。

Slightly frustrating as nothing in any logs indicated that this was a problem. 有点令人沮丧,因为任何日志中都没有任何内容表明这是一个问题。 Everything pretended to work, even though it was returning 404s. 即使返回404,一切都假装正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM