gpt4 book ai didi

java - 使用 Jenkins 将 Spring Boot WAR 部署到 Tomcat

转载 作者:行者123 更新时间:2023-11-28 23:25:34 26 4
gpt4 key购买 nike

我有一个 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,瞧,它运行得非常好。

有点令人沮丧,因为任何日志中都没有表明这是一个问题。一切都假装工作,即使它正在返回 404。

关于java - 使用 Jenkins 将 Spring Boot WAR 部署到 Tomcat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37624497/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com