gpt4 book ai didi

gradle - 如何用gradle构建WAR文件?

转载 作者:行者123 更新时间:2023-12-03 02:46:50 25 4
gpt4 key购买 nike

我想构建一个WAR文件(然后将其部署到Tomcat)。因此,作为练习,我在IDEA IntelliJ中使用Gradle启动了一个新的Spring Boot项目。之后,我将插件应用在build.gradle文件中,例如apply plugin: 'war'

问题是,当我尝试在终端中运行gradle war时,没有收到war文件!唯一发生的是它将生成一个带有3个子焊料\buildclassesresourcestmp,但是其中没有WAR。

我应该怎么做才能获得WAR文件?我看过this视频,但是这个人使用Maven,并且不做任何高级工作而是打仗。我认为必须有一种使其保持简单的方法。

当我运行gradle war --info

Initialized native services in: C:\Users\...\.gradle\native The client 

...

Task :compileJava UP-TO-DATE Resolving global dependency management for project 'deleteme' Excluding [org.apache.tomcat:tomcat-annotations-api] Excluding [] Skipping task ':compileJava' as it is up-to-date. :compileJava (Thread[Task worker for ':',5,main]) completed. Took 0.753 secs. :processResources (Thread[Task worker for ':',5,main]) started.

Task :processResources UP-TO-DATE Skipping task ':processResources' as it is up-to-date. :processResources (Thread[Task worker for ':',5,main]) completed. Took 0.003 secs. :classes (Thread[Task worker for ':',5,main]) started.

Task :classes UP-TO-DATE Skipping task ':classes' as it has no actions. :classes (Thread[Task worker for ':',5,main]) completed. Took 0.0 secs. :war (Thread[Task worker for ':',5,main]) started.

Task :war SKIPPED Skipping task ':war' as task onlyIf is false. :war (Thread[Task worker for ':',5,main]) completed. Took 0.0 secs.

最佳答案

我猜您除了war插件之外,还已经将spring boot gradle插件应用到了您的项目中?那么这种行为是正常的,因为Spring Boot插件将禁用jar和war任务,并将其替换为bootWar和bootJar任务。

在同时使用spring boot和war插件的情况下:

./gradlew war
15:35:09: Executing task 'war'...

> Task :compileJava UP-TO-DATE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :war SKIPPED

BUILD SUCCESSFUL in 0s
2 actionable tasks: 2 up-to-date
15:35:10: Task execution finished 'war'.

注意“跳过”消息
$ ./gradlew bootWar
15:36:35: Executing task 'bootWar'...

> Task :compileJava UP-TO-DATE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :bootWar

BUILD SUCCESSFUL in 1s
3 actionable tasks: 1 executed, 2 up-to-date
15:36:37: Task execution finished 'bootWar'.

然后,您将在build/libs下获得预期的war文件。

您仍然可以按照以下说明重新启用标准的jar/war任务: https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/html/#packaging-executable-wars-deployable(如果您需要生成普通存档而不是可执行存档)

关于Tomcat问题:安装Tomcat 8.5。

关于gradle - 如何用gradle构建WAR文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52314693/

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