我如何运行spring-boot 1.2.x可执行jar

时间:2015-02-17 02:03:01

标签: gradle spring-boot build.gradle

这是另一个得到部分回答的question的延续。自问题变形以来,我认为我应该打开一个更加内联的问题。

我有一个以spring-boot 1.1.7.RELEASE开头的项目,我从包含jar和application.properties文件的目录开始,通过:

java -jar edm-0.1.0.jar 

一切都是正确的雨,直到我升级到spring-boot 1.2.1.RELEASE。现在,当我尝试使用java -jar时,应用程序似乎已启动,但尝试登录时会出现错误,指出找不到/ templates html页面。

启动spring-boot应用程序的首选方法是:

gradle bootRun

只要我处于项目目录的顶层,这似乎就会起作用。但是,如果我将jar文件移到另一个目录,并尝试运行它,我会收到错误: :temp $ gradle bootRun

失败:构建因异常而失败。

* 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 tasks”时,我可以看到“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

这是我的build.gradle:

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'
}

我确实读过documentation,但似乎没有解决我遇到此问题的原因。我非常感谢你能给我的任何帮助。

0 个答案:

没有答案