Grails run-app:任务执行失败':bootRun'。错误:无法启动服务器

时间:2016-05-09 21:28:58

标签: grails gradle

尝试使用Gradle执行bootRun但我无法解决此错误:

| Running application...
objc[1566]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
INFO 5/9/16 4:10 PM: liquibase: Successfully acquired change log lock
INFO 5/9/16 4:10 PM: liquibase: Reading from PUBLIC.DATABASECHANGELOG
SEVERE 5/9/16 4:10 PM: liquibase: changelog.groovy: week-5A.groovy::1462469938896-1::Marco (generated): Change Set week-5A.groovy::1462469938896-1::Marco (generated) failed.  Error: Table "QUOTE" already exists; SQL statement:
CREATE TABLE PUBLIC.quote (id BIGINT AUTO_INCREMENT NOT NULL, version BIGINT NOT NULL, text VARCHAR(255) NOT NULL, CONSTRAINT quotePK PRIMARY KEY (id)) [42101-191] [Failed SQL: CREATE TABLE PUBLIC.quote (id BIGINT AUTO_INCREMENT NOT NULL, version BIGINT NOT NULL, text VARCHAR(255) NOT NULL, CONSTRAINT quotePK PRIMARY KEY (id))]
liquibase.exception.DatabaseException: Table "QUOTE" already exists; SQL statement:
CREATE TABLE PUBLIC.quote (id BIGINT AUTO_INCREMENT NOT NULL, version BIGINT NOT NULL, text VARCHAR(255) NOT NULL, CONSTRAINT quotePK PRIMARY KEY (id)) [42101-191] [Failed SQL: CREATE TABLE PUBLIC.quote (id BIGINT AUTO_INCREMENT NOT NULL, version BIGINT NOT NULL, text VARCHAR(255) NOT NULL, CONSTRAINT quotePK PRIMARY KEY (id))]
    at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:301)
    at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:55)
    at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:107)
    at liquibase.database.AbstractJdbcDatabase.execute(AbstractJdbcDatabase.java:1251)
    at liquibase.database.AbstractJdbcDatabase.executeStatements(AbstractJdbcDatabase.java:1234)
    at liquibase.changelog.ChangeSet.execute(ChangeSet.java:554)
    at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:51)
    at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:73)
    at liquibase.Liquibase.update(Liquibase.java:212)
    at liquibase.Liquibase.update(Liquibase.java:192)
    at liquibase.integration.spring.SpringLiquibase.performUpdate(SpringLiquibase.java:434)
    at org.grails.plugins.databasemigration.liquibase.GrailsLiquibase.performUpdate(GrailsLiquibase.groovy:80)
    at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:391)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766)
    at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
    at grails.boot.GrailsApp.run(GrailsApp.groovy:55)
    at grails.boot.GrailsApp.run(GrailsApp.groovy:365)
    at grails.boot.GrailsApp.run(GrailsApp.groovy:354)
    at grails.boot.GrailsApp$run.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
    at qotd.Application.main(Application.groovy:8)
Caused by: org.h2.jdbc.JdbcSQLException: Table "QUOTE" already exists; SQL statement:
CREATE TABLE PUBLIC.quote (id BIGINT AUTO_INCREMENT NOT NULL, version BIGINT NOT NULL, text VARCHAR(255) NOT NULL, CONSTRAINT quotePK PRIMARY KEY (id)) [42101-191]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
    at org.h2.message.DbException.get(DbException.java:179)
    at org.h2.message.DbException.get(DbException.java:155)
    at org.h2.command.ddl.CreateTable.update(CreateTable.java:115)
    at org.h2.command.CommandContainer.update(CommandContainer.java:98)
    at org.h2.command.Command.executeUpdate(Command.java:258)
    at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:184)
    at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:158)
    at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:299)
    ... 35 more
INFO 5/9/16 4:10 PM: liquibase: week-5A.groovy::1462469938896-1::Marco (generated): Successfully released change log lock
ERROR org.springframework.boot.SpringApplication - Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springLiquibase_dataSource': Invocation of init method failed; nested exception is liquibase.exception.MigrationFailedException: Migration failed for change set week-5A.groovy::1462469938896-1::Marco (generated):
     Reason: liquibase.exception.DatabaseException: Table "QUOTE" already exists; SQL statement:
CREATE TABLE PUBLIC.quote (id BIGINT AUTO_INCREMENT NOT NULL, version BIGINT NOT NULL, text VARCHAR(255) NOT NULL, CONSTRAINT quotePK PRIMARY KEY (id)) [42101-191] [Failed SQL: CREATE TABLE PUBLIC.quote (id BIGINT AUTO_INCREMENT NOT NULL, version BIGINT NOT NULL, text VARCHAR(255) NOT NULL, CONSTRAINT quotePK PRIMARY KEY (id))]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766)
    at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
    at grails.boot.GrailsApp.run(GrailsApp.groovy:55)
    at grails.boot.GrailsApp.run(GrailsApp.groovy:365)
    at grails.boot.GrailsApp.run(GrailsApp.groovy:354)
    at grails.boot.GrailsApp$run.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
    at qotd.Application.main(Application.groovy:8)
Caused by: liquibase.exception.MigrationFailedException: Migration failed for change set week-5A.groovy::1462469938896-1::Marco (generated):
     Reason: liquibase.exception.DatabaseException: Table "QUOTE" already exists; SQL statement:
CREATE TABLE PUBLIC.quote (id BIGINT AUTO_INCREMENT NOT NULL, version BIGINT NOT NULL, text VARCHAR(255) NOT NULL, CONSTRAINT quotePK PRIMARY KEY (id)) [42101-191] [Failed SQL: CREATE TABLE PUBLIC.quote (id BIGINT AUTO_INCREMENT NOT NULL, version BIGINT NOT NULL, text VARCHAR(255) NOT NULL, CONSTRAINT quotePK PRIMARY KEY (id))]
    at liquibase.changelog.ChangeSet.execute(ChangeSet.java:590)
    at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:51)
    at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:73)
    at liquibase.Liquibase.update(Liquibase.java:212)
    at liquibase.Liquibase.update(Liquibase.java:192)
    at liquibase.integration.spring.SpringLiquibase.performUpdate(SpringLiquibase.java:434)
    at org.grails.plugins.databasemigration.liquibase.GrailsLiquibase.performUpdate(GrailsLiquibase.groovy:80)
    at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:391)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
    ... 21 common frames omitted
Caused by: liquibase.exception.DatabaseException: Table "QUOTE" already exists; SQL statement:
CREATE TABLE PUBLIC.quote (id BIGINT AUTO_INCREMENT NOT NULL, version BIGINT NOT NULL, text VARCHAR(255) NOT NULL, CONSTRAINT quotePK PRIMARY KEY (id)) [42101-191] [Failed SQL: CREATE TABLE PUBLIC.quote (id BIGINT AUTO_INCREMENT NOT NULL, version BIGINT NOT NULL, text VARCHAR(255) NOT NULL, CONSTRAINT quotePK PRIMARY KEY (id))]
    at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:301)
    at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:55)
    at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:107)
    at liquibase.database.AbstractJdbcDatabase.execute(AbstractJdbcDatabase.java:1251)
    at liquibase.database.AbstractJdbcDatabase.executeStatements(AbstractJdbcDatabase.java:1234)
    at liquibase.changelog.ChangeSet.execute(ChangeSet.java:554)
    ... 30 common frames omitted
Caused by: org.h2.jdbc.JdbcSQLException: Table "QUOTE" already exists; SQL statement:
CREATE TABLE PUBLIC.quote (id BIGINT AUTO_INCREMENT NOT NULL, version BIGINT NOT NULL, text VARCHAR(255) NOT NULL, CONSTRAINT quotePK PRIMARY KEY (id)) [42101-191]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
    at org.h2.message.DbException.get(DbException.java:179)
    at org.h2.message.DbException.get(DbException.java:155)
    at org.h2.command.ddl.CreateTable.update(CreateTable.java:115)
    at org.h2.command.CommandContainer.update(CommandContainer.java:98)
    at org.h2.command.Command.executeUpdate(Command.java:258)
    at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:184)
    at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:158)
    at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:299)
    ... 35 common frames omitted

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':bootRun'.
> Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
| Error Failed to start server (Use --stacktrace to see the full trace)

这是我的build.gradle文件:

buildscript {
    ext {
        grailsVersion = project.grailsVersion
    }
    repositories {
        mavenLocal()
        maven { url "http://localhost:8081/nexus/content/groups/public/" }
    }
    dependencies {
        classpath "org.grails:grails-gradle-plugin:$grailsVersion"
        classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.7.4"
        classpath "org.grails.plugins:hibernate4:5.0.2"
     classpath "org.grails.plugins:database-migration:2.0.0.RC4"
    }
}

version "1.0.0-SNAPSHOT"
group "qotd"

apply plugin:"eclipse"
apply plugin:"idea"
apply plugin:"war"
apply plugin:"org.grails.grails-web"
apply plugin:"org.grails.grails-gsp"
apply plugin:"asset-pipeline"
apply plugin:"base"
apply plugin:"java"
apply plugin:"maven"

ext {
    grailsVersion = project.grailsVersion
    gradleWrapperVersion = project.gradleWrapperVersion
}

repositories {
    mavenLocal()
        maven { url "http://localhost:8081/nexus/content/groups/public/" }
}

dependencyManagement {
    imports {
        mavenBom "org.grails:grails-bom:$grailsVersion"
    }
    applyMavenExclusions false
}

dependencies {
    compile "org.springframework.boot:spring-boot-starter-logging"
    compile "org.springframework.boot:spring-boot-autoconfigure"
    compile "org.grails:grails-core"
    compile "org.springframework.boot:spring-boot-starter-actuator"
    compile "org.springframework.boot:spring-boot-starter-tomcat"
    compile "org.grails:grails-dependencies"
    compile "org.grails:grails-web-boot"
    compile "org.grails.plugins:cache"
    compile "org.grails.plugins:scaffolding"
    compile "org.grails.plugins:hibernate4"
    compile "org.hibernate:hibernate-ehcache"
    console "org.grails:grails-console"
    profile "org.grails.profiles:web:3.1.4"
    runtime "org.grails.plugins:asset-pipeline"
    runtime "com.h2database:h2"
    runtime "org.grails.plugins:database-migration:2.0.0.RC4"
    testCompile "org.grails:grails-plugin-testing"
    testCompile "org.grails.plugins:geb"
    testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
    testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
}
uploadArchives{
    repositories{
        mavenDeployer{
            repository(
            url: "${nexusUrl}/content/repositories/releases"){
                authentication(userName: nexusUsername,
                           password: nexusPassword)
            }
            snapshotRepository(
            url: "${nexusUrl}/content/repositories/snapshots"){
                authentication(userName: nexusUsername,
                           password: nexusPassword)
            }
        } 
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = gradleWrapperVersion
}

assets {
    minifyJs = true
    minifyCss = true
}

sourceSets{
    main{
        resources{
            srcDir 'grails-app/migrations'
    }
    }
}

这是一个每周以增量方式构建的类的项目。本周我们将更新域对象模型并执行数据库迁移。

这是应用程序文件:

---
hibernate:
    cache:
        queries: false
        use_second_level_cache: true
        use_query_cache: false
        region.factory_class: 'org.hibernate.cache.ehcache.EhCacheRegionFactory'

dataSource:
    pooled: true
    jmxExport: true
    driverClassName: org.h2.Driver
    username: sa
    password:

environments:
    development:
        dataSource:
            dbCreate: ""
            url: jdbc:h2:./quoteDB;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=TRUE
        grails:
            plugin:
                databasemigration:
                    updateOnStart: true
                    updateOnStartFileNames: [changelog.groovy]
    test:
        dataSource:
            dbCreate: update
            url: jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
    production:
        dataSource:
            dbCreate: update
            url: jdbc:h2:./prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
            properties:
                jmxEnabled: true
                initialSize: 5
                maxActive: 50
                minIdle: 5
                maxIdle: 25
                maxWait: 10000
                maxAge: 600000
                timeBetweenEvictionRunsMillis: 5000
                minEvictableIdleTimeMillis: 60000
                validationQuery: SELECT 1
                validationQueryTimeout: 3
                validationInterval: 15000
                testOnBorrow: true
                testWhileIdle: true
                testOnReturn: false
                jdbcInterceptors: ConnectionState
                defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED

---
---
grails:
    profile: web
    codegen:
        defaultPackage: qotd
    spring:
        transactionManagement:
            proxies: false
info:
    app:
        name: '@info.app.name@'
        version: '@info.app.version@'
        grailsVersion: '@info.app.grailsVersion@'
spring:

    groovy:
        template:
            check-template-location: false

---
grails:
    mime:
        disable:
            accept:
                header:
                    userAgents:
                        - Gecko
                        - WebKit
                        - Presto
                        - Trident
        types:
            all: '*/*'
            atom: application/atom+xml
            css: text/css
            csv: text/csv
            form: application/x-www-form-urlencoded
            html:
              - text/html
              - application/xhtml+xml
            js: text/javascript
            json:
              - application/json
              - text/json
            multipartForm: multipart/form-data
            pdf: application/pdf
            rss: application/rss+xml
            text: text/plain
            hal:
              - application/hal+json
              - application/hal+xml
            xml:
              - text/xml
              - application/xml
    urlmapping:
        cache:
            maxsize: 1000
    controllers:
        defaultScope: singleton
    converters:
        encoding: UTF-8
    views:
        default:
            codec: html
        gsp:
            encoding: UTF-8
            htmlcodec: xml
            codecs:
                expression: html
                scriptlets: html
                taglib: none
                staticparts: none
endpoints:
    jmx:
        unique-names: true

我尝试的事情:

  1. gradle clean assemble
  2. 重新启动计算机
  3. 确保我的$ JAVA_HOME变量已正确设置
  4. 删除数据库文件(由教授收录)
  5. 不是已使用的地址(使用pid手动检查)
  6. 谢谢你看看!

3 个答案:

答案 0 :(得分:2)

问题是我的changelog和第5a周脚本都在做同样的事情,即创建数据库。在更改日志内部有一行代码include file: 'week-5A.groovy'。因此,当执行更改日志时,它会创建数据库,然后执行第5A周,后者继续执行相同的操作,因此引发了异常。

答案 1 :(得分:0)

当hibernate尝试执行sql语句时 作为流程

CREATE TABLE PUBLIC.quote (id BIGINT AUTO_INCREMENT NOT NULL, version BIGINT NOT NULL, text VARCHAR(255) NOT NULL, CONSTRAINT quotePK PRIMARY KEY (id)) [42101-191] [Failed SQL: CREATE TABLE PUBLIC.quote (id BIGINT AUTO_INCREMENT NOT NULL, version BIGINT NOT NULL, text VARCHAR(255) NOT NULL, CONSTRAINT quotePK PRIMARY KEY (id))]

数据库发现这个名为“PUBLIC.quote”的表存在。

“自动数据库迁移”选项可能不正确。您可以在开发环境中将“dbCreate”选项设置为“update”

答案 2 :(得分:0)

在你的liquibase scrips周围进行一些先决条件检查是个好主意:

http://www.liquibase.org/documentation/preconditions.html

类似的东西:

    preConditions(onFail:"MARK_RAN") {
        not {
            tableExists(tableName: "quote")
        }
    }