Java Can';t为spring boot web项目创建war归档
我已经用Intellij创建了SpringBootWeb项目,在用SpringApplication.run()方法构建或启动项目之后,我在任何地方都看不到我的web存档。在文档页面上,我发现了三个应该遵守的条款Java Can';t为spring boot web项目创建war归档,java,spring-boot,build.gradle,Java,Spring Boot,Build.gradle,我已经用Intellij创建了SpringBootWeb项目,在用SpringApplication.run()方法构建或启动项目之后,我在任何地方都看不到我的web存档。在文档页面上,我发现了三个应该遵守的条款 生成可部署war文件的第一步是提供SpringBootServletilizer 将war插件应用于项目 通过添加 providedRuntime'org.springframework.boot:springbootstartertomcat' 建立脚本 我的servlet初始值设定
providedRuntime'org.springframework.boot:springbootstartertomcat'
建立脚本public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(RegTemplateApplication.class);
}
}
我的构建脚本
buildscript {
ext {
springBootVersion = '1.5.3.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
configurations {
providedRuntime
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-web')
runtime('com.h2database:h2')
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
要组装war,您应该运行
gradle assemble
默认情况下,此命令将从src/main/webapp
源创建war工件。
还要检查您的源是否在该目录中,或者您应该提供webAppDirName
属性
请参见我尝试使用以下方法构建:
gradle clean build
并在以下目录中找到web存档:
./build/libs/build.war
注意:您必须在您的计算机上安装gradle。我可以使用IntelliJ 2016和Maven创建一场战争。我现在手头没有密码。我会努力找到它的。我看不到你需要的插件。你能在Gradle设置中突出显示它吗?我不确定graidle是否可以,但是maven可以运行mvn包,并在/target文件夹中生成WAR文件。运行应用程序当然不会创建WAR。您必须在命令行上(或从IntelliJ中)使用
gradle build
来创建工件。正如名字所说,运行应用程序就是运行应用程序。