読者です 読者をやめる 読者になる 読者になる

ゲンゾウ用ポストイット

Java、Groovy、Linux関連の備忘録

GriffonでHibernateのアノテーションを使いたい時に躓いた

Griffonでアプリケーションを作成する機会が増えてきた。
SQliteが気に入っていてよく使っていたがHibernateを利用したかったため実績のあるHsqldbに切り替えた。

griffon-app/conf/Config.groovyに以下の記載を追加すればすぐに使えるものと思っていた。

    dependencies {
        ...
        compile "org.hibernate:hibernate-annotations:3.5.6-Final"
        runtime "org.slf4j:slf4j-simple:1.4.2"
        runtime "hsqldb:hsqldb:1.8.0.7"
        runtime "javassist:javassist:3.4.GA"
        runtime "org.hibernate:hibernate-validator:4.2.0.Final"
        ...
    }

が、どうもよくわからないエラーが発生。

java.lang.LinkageError: loader constraint violation: when resolving overridden method "org.apache.tools.ant.helper.ProjectHelper2$RootHandler.setDocumentLocator(Lorg/xml/sax/Locator;)V" the class loader (instance of org/codehaus/griffon/cli/support/GriffonRootLoader) of the current class, org/apache/tools/ant/helper/ProjectHelper2$RootHandler, and its superclass loader (instance of <bootloader>), have different Class objects for the type andler.setDocumentLocator(Lorg/xml/sax/Locator;)V used in the signature
	at org.apache.tools.ant.helper.ProjectHelper2.parseUnknownElement(ProjectHelper2.java:130)
	at org.apache.tools.ant.helper.ProjectHelper2.parseAntlibDescriptor(ProjectHelper2.java:110)
	at org.apache.tools.ant.taskdefs.Antlib.createAntlib(Antlib.java:91)
	at org.apache.tools.ant.taskdefs.Definer.loadAntlib(Definer.java:440)
	at org.apache.tools.ant.taskdefs.Definer.execute(Definer.java:292)
	at org.apache.tools.ant.ComponentHelper.checkNamespace(ComponentHelper.java:869)
	at org.apache.tools.ant.ComponentHelper.getDefinition(ComponentHelper.java:308)
	at org.apache.tools.ant.ComponentHelper.createComponent(ComponentHelper.java:285)
	at org.apache.tools.ant.ComponentHelper.createComponent(ComponentHelper.java:264)
	at org.apache.tools.ant.UnknownElement.makeObject(UnknownElement.java:417)
	at org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:163)
	at org.codehaus.griffon.cli.GriffonScriptRunner.callPluginOrGriffonScript(GriffonScriptRunner.java:435)
	at org.codehaus.griffon.cli.GriffonScriptRunner.executeCommand(GriffonScriptRunner.java:300)
	at org.codehaus.griffon.cli.GriffonScriptRunner.main(GriffonScriptRunner.java:116)
	at org.codehaus.griffon.cli.support.GriffonStarter.rootLoader(GriffonStarter.java:198)
	at org.codehaus.griffon.cli.support.GriffonStarter.main(GriffonStarter.java:223)
Error executing script RunApp: loader constraint violation: when resolving overridden method "org.apache.tools.ant.helper.ProjectHelper2$RootHandler.setDocumentLocator(Lorg/xml/sax/Locator;)V" the class loader (instance of org/codehaus/griffon/cli/support/GriffonRootLoader) of the current class, org/apache/tools/ant/helper/ProjectHelper2$RootHandler, and its superclass loader (instance of <bootloader>), have different Class objects for the type andler.setDocumentLocator(Lorg/xml/sax/Locator;)V used in the signature

いろいろ試してみた結果、hibernate-annotasionsライブラリ内のxml-apiを以下のように除外してやる必要があった。

    dependencies {
        ...
        compile( "org.hibernate:hibernate-annotations:3.5.6-Final" ){
            excludes 'xml-apis', 'xerces'
        }
        runtime "org.slf4j:slf4j-simple:1.4.2"
        runtime "hsqldb:hsqldb:1.8.0.7"
        runtime "javassist:javassist:3.4.GA"
        runtime "org.hibernate:hibernate-validator:4.2.0.Final"
        ...
    }

Griffonのマニュアルに書いてあるかも。