Gradle 如何运行SpringBoot1.2.x可执行jar
这是另一个得到部分回答的问题的延续。既然问题发生了变化,我想我应该提出一个更符合这一点的问题 我有一个项目从spring boot 1.1.7.RELEASE开始,我从一个包含jar和application.properties文件的目录开始,通过:Gradle 如何运行SpringBoot1.2.x可执行jar,gradle,spring-boot,build.gradle,Gradle,Spring Boot,Build.gradle,这是另一个得到部分回答的问题的延续。既然问题发生了变化,我想我应该提出一个更符合这一点的问题 我有一个项目从spring boot 1.1.7.RELEASE开始,我从一个包含jar和application.properties文件的目录开始,通过: java -jar edm-0.1.0.jar 在我升级到spring boot 1.2.1.0版本之前,一切正常。现在,当我尝试使用java-jar启动时,应用程序似乎启动了,但尝试登录时会出现一个错误,即找不到/templates/html
java -jar edm-0.1.0.jar
在我升级到spring boot 1.2.1.0版本之前,一切正常。现在,当我尝试使用java-jar启动时,应用程序似乎启动了,但尝试登录时会出现一个错误,即找不到/templates/html页面
似乎启动spring启动应用程序的首选方式是:
gradle bootRun
只要我在项目目录的顶层,这似乎就可以工作。但如果我将jar文件移到另一个目录,并尝试运行它,则会出现错误:
:temp$gradle引导运行
失败:生成失败,出现异常
* What went wrong:
Task 'bootRun' not found in root project 'temp'.
* Try:
Run gradle tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
因此,当我运行gradle任务时,我可以看到bootRun不可用:
:temp$ gradle tasks
:tasks
------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------
Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]
Help tasks
----------
dependencies - Displays all dependencies declared in root project 'temp'.
dependencyInsight - Displays the insight into a specific dependency in root project 'temp'.
help - Displays a help message
projects - Displays the sub-projects of root project 'temp'.
properties - Displays the properties of root project 'temp'.
tasks - Displays the tasks runnable from root project 'temp'.
我想这是一个春靴渐变的问题,但我不能肯定。我的版本:
:temp$ gradle -version
------------------------------------------------------------
Gradle 1.10
------------------------------------------------------------
Build time: 2013-12-17 09:28:15 UTC
Build number: none
Revision: 36ced393628875ff15575fa03d16c1349ffe8bb6
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.9.2 compiled on July 8 2013
Ivy: 2.2.0
JVM: 1.8.0_31 (Oracle Corporation 25.31-b07)
OS: Mac OS X 10.10.2 x86_64
这是我的身材。格雷德尔:
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'jacoco'
apply plugin: 'maven'
idea {
project {
//if you want to set specific jdk and language level
jdkName = '1.8'
languageLevel = '1.8'
}
}
jacoco {
toolVersion = "0.7.0.201403182114"
}
project.ext {
springBootVersion = '1.2.1.RELEASE'
}
configurations {
querydslapt
}
buildscript {
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url "http://repo.spring.io/libs-milestone" }
maven { url "http://repo.spring.io/libs-snapshot" }
mavenLocal()
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.1.RELEASE")
}
}
jar {
baseName = 'edm'
version = '0.1.0'
}
repositories {
mavenCentral()
maven { url "http://repo.spring.io/libs-milestone" }
maven { url "https://repository.jboss.org/nexus/content/repositories/releases" }
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url "http://repo.spring.io/snapshot" }
maven { url 'http://repo.spring.io/milestone' }
}
dependencies {
querydslapt group: 'com.mysema.querydsl', name: 'querydsl-jpa', version: '2.8.0', classifier: 'apt-one-jar', transitive: false
compile("org.springframework.boot:spring-boot-starter-web:$springBootVersion")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-starter-security")
compile("org.springframework.boot:spring-boot-starter-data-jpa:$springBootVersion")
compile("org.springframework.security:spring-security-web:4.0.0.M1")
compile("org.springframework.security:spring-security-config:4.0.0.M1")
compile('org.thymeleaf.extras:thymeleaf-extras-springsecurity3:2.1.1.RELEASE')
compile('com.android.tools.build:gradle:1.0.1')
task wrapper(type: Wrapper) {
gradleVersion = '2.0'
}
我确实读过这本书,但似乎没有任何东西能解释我为什么会有这个问题。我非常感谢您能为我提供的任何帮助。您的项目是否在线托管?试一试?看来,启动spring启动应用程序的首选方式是gradle bootRun——我不认为这是许多人的首选,当然也不会取代java-jar。。。生产中的选择权。您现在有两个问题:如何从gradle运行应用程序?以及如何修复坏罐子中的HTML模板路径?。我建议你决定要问哪一个问题,然后修改这个问题,或者把它分成两部分。可能重复我在另一个问题中建议使用gradle bootRun,不是因为这是一种推荐的运行应用程序的方法,而是为了缩小问题的范围。现在,您已经发布了两个问题,它们本质上是在问同一个问题,但这两个问题都没有包含足够的信息来诊断问题。我建议您阅读并相应更新其中一个问题。我为困惑道歉,我认为我面临两个相关问题,最好是提出两个具体问题。另一个是关于使用java-jar错误地运行项目,另一个是关于使用gradle bootRun。另外,在@Andy建议使用gradle bootRun之后,我觉得我的问题与gradle有关,而不是与jar文件有关。我将关闭这个,然后返回到那个。我真的很想帮助你理解为什么这行不通。