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

MacOS10.5.7でGrailsがJava1.5.0_19を使ってしまってる件

インタフェースの実装メソッドに書いた@Overrideがエラーになったので気づいた。


なんでやねん。

$ java -version
java version "1.6.0_13"
Java(TM) SE Runtime Environment (build 1.6.0_13-b03-211)
Java HotSpot(TM) 64-Bit Server VM (build 11.3-b02-83, mixed mode)

という環境で、

$ grails create-script java-version
$ vim scripts/JavaVersion.groovy
includeTargets << grailsScript("Init")

target(main: "display java version") {
    println "java.version" + System.getProperty("java.version")
}

setDefaultTarget(main)


と、確認用のGrailsスクリプトを書いて実行すると・・・

$ grails java-version
Welcome to Grails 1.1.1 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /Users/nobeans/Developer/grails/grails-1.1.1
Base Directory: /Users/nobeans/Developer/grails/sample
Running script /Users/nobeans/Developer/grails/sample/scripts/JavaVersion.groovy
Environment set to development
Warning, target causing name overwriting of name default
java.version1.5.0_19


となる。おいおい、どっから見つけてきたんよ。
Java PreferenceでもJava SE 6 (64bit)が先頭になってるのに。


Java6どこいってもうたんや・・・。



↓これを見つけて複雑すぎる構成にうんざりしてるところ。
Mac Java の複雑な階層構成のまとめと管理 | Apribase

単に、

$ sudo rm /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
$ sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.6 /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
$ export JAVA_HOME=/Library/Java/Home

としただけだと、

$ grails java-version
Welcome to Grails 1.1.1 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /Users/nobeans/Developer/grails/grails-1.1.1

Base Directory: /Users/nobeans/Developer/grails/sample
Running script /Users/nobeans/Developer/grails/sample/scripts/JavaVersion.groovy
Environment set to development
[Deprecated] CocoaJava: com.apple.cocoa.foundation.NSDictionary
NSRuntime.loadLibrary(/usr/lib/java/libObjCJava.dylib) error.
java.lang.UnsatisfiedLinkError: /usr/lib/java/libObjCJava.A.dylib:  no suitable image found.  Did find:  /usr/lib/java/libObjCJava.A.dylib: no matching architecture in universal wrapper
	at java.lang.ClassLoader$NativeLibrary.load(Native Method)
	at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1881)
	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1761)
	at java.lang.Runtime.load0(Runtime.java:770)
	at java.lang.System.load(System.java:1022)
	at com.apple.cocoa.foundation.NSRuntime.loadLibrary(NSRuntime.java:127)
	at com.apple.cocoa.foundation.NSRuntime.<clinit>(NSRuntime.java:35)
	at com.apple.cocoa.foundation.NSObject.<clinit>(NSObject.java:27)
	at com.growl.Growl.<init>(Growl.java:116)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
	at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
	at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:107)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:52)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:192)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:204)
	at _Events.run(_Events.groovy:17)
	at org.codehaus.groovy.grails.cli.support.GrailsBuildEventListener.loadEventsScript(GrailsBuildEventListener.java:103)
	at org.codehaus.groovy.grails.cli.support.GrailsBuildEventListener.loadEventHooks(GrailsBuildEventListener.java:67)
	at org.codehaus.groovy.grails.cli.support.GrailsBuildEventListener.initialize(GrailsBuildEventListener.java:54)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:229)
	at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:121)
	at _GrailsEvents_groovy.run(_GrailsEvents_groovy:55)
	at _GrailsEvents_groovy$run.call(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
	at _GrailsArgParsing_groovy$run.call(Unknown Source)
	at org.codehaus.gant.IncludeTargets.leftShift(IncludeTargets.groovy:59)
	at org.codehaus.gant.IncludeTargets$leftShift.call(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
	at _GrailsArgParsing_groovy.run(_GrailsArgParsing_groovy:29)
	at _GrailsArgParsing_groovy$run.call(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
	at _GrailsInit_groovy$run.call(Unknown Source)
	at org.codehaus.gant.IncludeTargets.leftShift(IncludeTargets.groovy:59)
	at org.codehaus.gant.IncludeTargets$leftShift.call(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
	at _GrailsInit_groovy.run(_GrailsInit_groovy:35)
	at _GrailsInit_groovy$run.call(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
	at Init_groovy$run.call(Unknown Source)
	at org.codehaus.gant.IncludeTargets.leftShift(IncludeTargets.groovy:59)
	at org.codehaus.gant.IncludeTargets$leftShift.call(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
	at Init_groovy.run(Init_groovy:30)
	at Init_groovy$run.call(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:121)
	at org.codehaus.gant.IncludeTargets.leftShift(IncludeTargets.groovy:59)
	at org.codehaus.gant.IncludeTargets$leftShift.call(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
	at JavaVersion.run(JavaVersion:1)
	at JavaVersion$run.call(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:121)
	at gant.Gant.processTargets(Gant.groovy:494)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:266)
	at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:155)
	at gant.Gant.processTargets(Gant.groovy:480)
	at org.codehaus.groovy.grails.cli.GrailsScriptRunner.callPluginOrGrailsScript(GrailsScriptRunner.java:409)
	at org.codehaus.groovy.grails.cli.GrailsScriptRunner.executeCommand(GrailsScriptRunner.java:279)
	at org.codehaus.groovy.grails.cli.GrailsScriptRunner.main(GrailsScriptRunner.java:106)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.codehaus.groovy.grails.cli.support.GrailsStarter.rootLoader(GrailsStarter.java:187)
	at org.codehaus.groovy.grails.cli.support.GrailsStarter.main(GrailsStarter.java:212)


という無残なことになった。



はて、どうしたらよいものだろうか。

2009/07/10追記

どうやら、64bit版のCocoa-Javaブリッジがないためっぽい?


前述のエラーで

[Deprecated] CocoaJava: com.apple.cocoa.foundation.NSDictionary
NSRuntime.loadLibrary(/usr/lib/java/libObjCJava.dylib) error.
java.lang.UnsatisfiedLinkError: /usr/lib/java/libObjCJava.A.dylib:  no suitable image found.  Did find:  /usr/lib/java/libObjCJava.A.dylib: no matching architecture in universal wrapper

とロードに失敗しているっぽいlibObjCJava.A.dylibを調べてみると

$ lipo -info /usr/lib/java/libObjCJava.A.dylib
Architectures in the fat file: /usr/lib/java/libObjCJava.A.dylib are: i386 ppc7400

とでます。確かに対応アーキテクチャx86_64が入ってない。


えーと、結局どういうことなんだろう?
(たぶん、つづく)