gpt4 book ai didi

spring-boot - 使用Gradle使用JSP页面为Spring Boot Application创建Jar

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

我有一个SpringBoot应用程序,其中没有几个JSP页面。当我从 eclipse 启动主类时,它运行良好。但是同时,当我将其打包为jar时,WEB-INF/jsp文件夹配置不正确。我被困在这里。请求您的帮助

以下是我的Gradle脚本

buildscript {
ext {
springBootVersion = '1.5.4.RELEASE'
}
repositories {

maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'

group = 'com.arun'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

task packSSO(type: Jar) {
manifest {
attributes(
'Implementation-Title': 'Arun Spring Boot Application',
'Implementation-Version': version,
'Built-By': System.getProperty('user.name'),
'Built-Date': new Date(),
'Main-Class': 'com.arun.MainGate',
'Built-JDK': System.getProperty('java.version')
)
}
sourceSets {
main {
resources {
srcDirs "src/main/resources"
}
}
}
baseName = project.name + '-all'
from {
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
}
with jar
}





repositories {

maven {
url "https://plugins.gradle.org/m2/"
}
}


dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-tomcat')
compile('org.apache.tomcat.embed:tomcat-embed-jasper')
compile ('javax.servlet:jstl:1.2')
testCompile('org.springframework.boot:spring-boot-starter-test')
testImplementation 'junit:junit:4.12'
}

我分解了创建的Jar,其结构如下所示。

enter image description here

因此,当我运行 java -jar SSOPage-0.0.1-SNAPSHOT.jar时,找不到JSP页面。我应该遵循什么确切的文件夹结构以及如何在gradle中打包 WEB-INF

最佳答案

我认为您必须对使用JSP的Spring Boot应用程序使用WAR打包。但是,您仍然可以像$ java -jar ./build/libs/hcro-pdi-1.0.0.war一样使用它作为独立的可执行JAR文件。

这是我使用JSP的Spring Boot 2.0.1项目中的build.gradle文件。

plugins {
id 'org.springframework.boot' version '2.0.1.RELEASE'
id "io.spring.dependency-management" version "1.0.4.RELEASE"
}

apply plugin: 'org.springframework.boot'
apply plugin: 'war'

bootWar {
baseName = 'hcro-pdi'
version = '1.0.0'
}

gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
}

repositories {
mavenCentral()
}

dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
compile('org.springframework.boot:spring-boot-starter-jdbc')
compile('javax.servlet:jstl')
compile('org.apache.tomcat.embed:tomcat-embed-jasper')

// Devtools enable hot-reloading of JSP and static content
compile("org.springframework.boot:spring-boot-devtools")

compile(group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '2.2.0')
compile(group: 'org.apache.commons', name: 'commons-lang3', version: '3.7')
compile(group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.5')
compile(group: 'joda-time', name: 'joda-time')
compile(group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-joda')

compileOnly('org.projectlombok:lombok')
testCompile('org.springframework.boot:spring-boot-starter-test')

}

// When running in bootRun task, automatically reload static resources when changed
// https://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-gradle-plugin.html#build-tool-plugins-gradle-running-applications
bootRun {
jvmArgs "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"
sourceResources sourceSets.main
}

并且,您必须将这两个属性添加到@Yogi共享的 application.properties中。
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp

关于spring-boot - 使用Gradle使用JSP页面为Spring Boot Application创建Jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46891272/

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