2016-07-02 37 views
1

我是Liquibase和JHipster的新手,並且在使用maven插件生成diff時遇到了一些問題。liquibase.exception.DatabaseException:java.lang.ClassNotFoundException

運行mvn liquibase:diff -e -X

我的聚甲醛的有關章節時,我收到以下錯誤:

<plugin> 
      <groupId>org.liquibase</groupId> 
      <artifactId>liquibase-maven-plugin</artifactId> 
      <version>${liquibase.version}</version> 
      <dependencies> 
       <dependency> 
        <groupId>org.javassist</groupId> 
        <artifactId>javassist</artifactId> 
        <version>3.18.2-GA</version> 
       </dependency> 
       <dependency> 
        <groupId>org.liquibase.ext</groupId> 
        <artifactId>liquibase-hibernate4</artifactId> 
        <version>${liquibase-hibernate4.version}</version> 
       </dependency> 
       <dependency> 
        <groupId>org.springframework.boot</groupId> 
        <artifactId>spring-boot-starter-data-jpa</artifactId> 
        <version>${project.parent.version}</version> 
       </dependency> 
       <dependency> 
        <groupId>org.hibernate</groupId> 
        <artifactId>hibernate-core</artifactId> 
        <version>5.2.1.Final</version> 
       </dependency> 

      </dependencies> 
      <configuration> 
       <changeLogFile>src/main/resources/config/liquibase/master.xml</changeLogFile> 
       <diffChangeLogFile> 
        src/main/resources/config/liquibase/changelog/${maven.build.timestamp}_changelog.xml 
       </diffChangeLogFile> 
       <driver>org.postgresql.Driver</driver> 
       <url>jdbc:postgresql://localhost/shiftwork</url> 
       <defaultSchemaName/> 
       <username>postgres</username> 
       <password/> 
       <referenceUrl>hibernate:spring:com.teammachine.staffrostering.domain?dialect=org.hibernate.dialect.PostgreSQL94Dialect&amp;hibernate.ejb.naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringNamingStrategy</referenceUrl> 
       <verbose>true</verbose> 
       <logging>debug</logging> 
      </configuration> 
     </plugin> 
     <changeLogFile>src/main/resources/config/liquibase/master.xml</changeLogFile> 
     <diffChangeLogFile> 
      src/main/resources/config/liquibase/changelog/${maven.build.timestamp}_changelog.xml 
     </diffChangeLogFile> 
     <driver>org.postgresql.Driver</driver> 
     <url>jdbc:postgresql://localhost/myApp</url> 
     <defaultSchemaName/> 
     <username>postgres</username> 
     <password/> 
     <referenceUrl>hibernate:spring:com.myapp.domain?dialect=&amp;hibernate.ejb.naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringNamingStrategy</referenceUrl> 
     <verbose>true</verbose> 
     <logging>debug</logging> 
    </configuration> 
</plugin> 

也許我錯了,但我的理解是缺少類(org.hibernate作爲.boot)是Hibernate Core的一部分,它包含在內。

Number of foreign imports: 1 
import: Entry[import from realm ClassRealm[maven.api, parent: null]] 

----------------------------------------------------- 

    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:166) 
    ... 21 more 
Caused by: java.lang.NoClassDefFoundError: org/hibernate/boot/registry/classloading/internal/ClassLoaderServiceImpl$Work 
    at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:45) 
    at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:57) 
    at liquibase.ext.hibernate.database.HibernateSpringDatabase.buildConfigurationFromScanning(HibernateSpringDatabase.java:243) 
    at liquibase.ext.hibernate.database.HibernateSpringDatabase.buildConfiguration(HibernateSpringDatabase.java:55) 
    at liquibase.ext.hibernate.database.HibernateDatabase.setConnection(HibernateDatabase.java:45) 
    at liquibase.database.DatabaseFactory.findCorrectDatabaseImplementation(DatabaseFactory.java:131) 
    at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:151) 
    at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:85) 
    at org.liquibase.maven.plugins.LiquibaseDatabaseDiff.performLiquibaseTask(LiquibaseDatabaseDiff.java:166) 
    at org.liquibase.maven.plugins.AbstractLiquibaseMojo.execute(AbstractLiquibaseMojo.java:394) 
    at org.liquibase.maven.plugins.LiquibaseDatabaseDiff.execute(LiquibaseDatabaseDiff.java:146) 
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134) 
    ... 21 more 
Caused by: java.lang.ClassNotFoundException: org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl$Work 
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50) 
    at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271) 
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247) 
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239) 
    ... 33 more 
[ERROR] 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles: 
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException 
[email protected]:~/git/hughestech/shiftwork/staffservice$ 

回答

0

的問題是,你離開了dialect財產空白liquibase-maven-plugin配置的referenceUrl內。插件tries to look for that blank class,當然,失敗。 This should point給實現用於Hibernate的自定義方言的類。

<referenceUrl>hibernate:spring:com.myapp.domain?dialect=&amp;hibernate.ejb.naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringNamingStrategy</referenceUrl> 
<!--           ^^^^^^^^ --> 

如果您使用的是PostgreSQL,它取決於數據庫的版本。對於PostgreSQL 9.4或更高版本,您可以使用類org.hibernate.dialect.PostgreSQL94Dialect作爲方言。

因此,更新你的配置是:

<referenceUrl>hibernate:spring:com.myapp.domain?dialect=org.hibernate.dialect.PostgreSQL94Dialect&amp;hibernate.ejb.naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringNamingStrategy</referenceUrl> 

你還取決於衝突的Hibernate版本的插件的依賴:liquibase-hibernate4requires Hibernate 4.3+但你依賴於Hibernate的核心5.2.1。最終和they are not compatible。因此,您需要刪除對hibernate-core的這種依賴關係。

+0

謝謝。我已經添加了這個並更新了我的問題。 – Magick

+1

@Magick這是由衝突版本的Hibernate引起的不同錯誤。因爲這個問題真的不相關,所以最好發表一個新的問題。在這個新問題中,請確保發佈Liquibase和Hibernate的確切版本。因爲Liquibase依賴於Hibernate 4,所以我會嘗試去除對'hibernate-core' 5的依賴。 – Tunaki

+0

@Magick我做了一個編輯。 – Tunaki