No Programming, No Life

プログラミング関連の話題や雑記

Mac OSXにOpenJDK7をインストールしてGroovyを実行する

こちら@yusukeyさんの記事を参考にMac OSXにOpenJDK7をインストールしてGroovyを実行するところまで試してみたのでメモしておきます。

1.まずはOpenJDK7をダウンロード

Mac OSX用のバイナリが以下から手に入るのでダウンロードしてきます。
http://code.google.com/p/openjdk-osx-build/downloads/list
ひとまずこれを書いてる時点の最新バージョンである

OpenJDK-OSX-1.7-universal-20110729.dmg

をダウンロードしてきました。

2.インストール

  • OpenJDK-OSX-1.7-universal-20110729.dmg をダブルクリック
  • デュークをクリック

f:id:fumokmm:20110730160238p:image

  • 続ける(どんどん進む)

f:id:fumokmm:20110730160237p:image

  • インストール完了

f:id:fumokmm:20110730160236p:image

3.インストール確認

open /Applications/Utilities/Java\ Preferences.app

f:id:fumokmm:20110730161010p:image

Open JDK7が入りました。

4.環境変数JAVA_HOMEの設定

Open JDK7は以下にインストールされるようなので、以下を環境変数JAVA_HOMEに設定します。

/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home

私の環境だとJAVA_HOMEは以下となっていました。

$ echo $JAVA_HOME
/Library/Java/Home

確認してみるとHOMEはシンボリックリンクだったので、ひとまず、今のHOMEはHome6として残しておき、Java7用としてはHome7という名前でシンボリックリンクを作成することにしました。
$ ln -s /System/Library/Frameworks/JavaVM.framework/Home /Library/Java/Home6
$ ln -s /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home /Library/Java/HOME7
$ rm /Library/Java/Home

次に.profileを以下のように編集します。

#export JAVA_HOME=/Library/Java/Home6
export JAVA_HOME=/Library/Java/Home7

いつでもHome6に戻せるようにHome6はコメントアウトしておきます。

$ . ~/.profile
$ java -version
openjdk version "1.7.0-internal"
OpenJDK Runtime Environment (build 1.7.0-internal-b00)
OpenJDK 64-Bit Server VM (build 21.0-b17, mixed mode)

1.7にちゃんとなってます。

5.Groovyの実行

バージョン確認

$ groovy -v
Groovy Version: 1.9.0-beta-1 JVM: 1.7.0-internal

スクリプト実行

$ cat hello.groovy 
println 'Hello, Groovy! with JDK7'
$ groovy hello.groovy
Hello, Groovy! with JDK7

スクリプト、実行できました。

GroovyShell実行

$ groovysh
Groovy Shell (1.9.0-beta-1, JVM: 1.7.0-internal)
Type 'help' or '\h' for help.

                                                                                                                                                                                                                                            • -

groovy:000> assert 1_0_0 + 2_0_0 == 3____00
===> null
groovy:000> assert 255 == 0b11111111
===> null
groovy:000> println 'Hello!'
Hello!
===> null
groovy:000>


GroovyShellも動きました。

GroovyConsole実行

$ groovyConsole &
/Applications/Utilities 557 $ java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108)
at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130)
Caused by: java.lang.NoClassDefFoundError: com/apple/eawt/ApplicationListener
at com.apple.mrj.MRJApplicationUtils.registerAboutHandler(MRJApplicationUtils.java:64)
at com.apple.mrj.MRJApplicationUtils$registerAboutHandler.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at groovy.ui.script13120101426311558877614.run(script13120101426311558877614.groovy:22)
at groovy.util.FactoryBuilderSupport.build(FactoryBuilderSupport.java:1117)
at groovy.util.FactoryBuilderSupport.build(FactoryBuilderSupport.java:1103)
at groovy.util.FactoryBuilderSupport.build(FactoryBuilderSupport.java:1121)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1052)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:882)
at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:785)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:768)
at groovy.util.FactoryInterceptorMetaClass.invokeMethod(FactoryBuilderSupport.java:1274)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:145)
at groovy.ui.view.MacOSXMenuBar.run(MacOSXMenuBar.groovy:46)
at groovy.util.FactoryBuilderSupport.build(FactoryBuilderSupport.java:1117)
at groovy.util.FactoryBuilderSupport.build(FactoryBuilderSupport.java:1103)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:361)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:882)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
at groovy.ui.Console$__clinit__closure23.doCall(Console.groovy:260)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:882)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:39)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at groovy.ui.ConsoleView$_run_closure1.doCall(ConsoleView.groovy:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:882)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
at groovy.ui.ConsoleView$_run_closure1.doCall(ConsoleView.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:882)
at groovy.lang.Closure.call(Closure.java:410)
at groovy.lang.Closure.call(Closure.java:404)
at groovy.util.FactoryBuilderSupport.dispathNodeCall(FactoryBuilderSupport.java:838)
at groovy.util.FactoryBuilderSupport.doInvokeMethod(FactoryBuilderSupport.java:744)
at groovy.util.FactoryBuilderSupport.invokeMethod(FactoryBuilderSupport.java:464)
at groovy.util.FactoryInterceptorMetaClass.invokeMethod(FactoryBuilderSupport.java:1272)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:145)
at groovy.ui.ConsoleView.run(ConsoleView.groovy:51)
at groovy.util.FactoryBuilderSupport.build(FactoryBuilderSupport.java:1117)
at groovy.util.FactoryBuilderSupport.build(FactoryBuilderSupport.java:1103)
at groovy.util.FactoryBuilderSupport$build.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at groovy.ui.Console.run(Console.groovy:301)
at groovy.ui.Console$run$0.callCurrent(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
at groovy.ui.Console.run(Console.groovy:264)
at groovy.ui.Console$run.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
at groovy.ui.Console.main(Console.groovy:199)
... 6 more
Caused by: java.lang.ClassNotFoundException: com.apple.eawt.ApplicationListener
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 108 more