SHIBUYA 3%

(元在宅が)渋谷で働くエンジニアの備忘録的memo & 雑記 - ココロはいつもSHIBUYAに在り

MacにJava9を入れてjshellを動かすまでのメモ

環境

インストール

JDK 9 Early Access Releases — Project Kenai

f:id:fukurou31:20160205011324p:plain

完了して確認

$ /usr/libexec/java_home -V
Matching Java Virtual Machines (5):
    9, x86_64:    "Java SE 9-ea"    /Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home
    1.8.0_60, x86_64:    "Java SE 8"    /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home
    1.7.0_79, x86_64:    "Java SE 7"    /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home
    1.6.0_65-b14-468, x86_64:    "Java SE 6"    /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    1.6.0_65-b14-468, i386:    "Java SE 6"    /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home

jshell起動 & エラー

$ export JAVA_HOME=`/usr/libexec/java_home -v 1.9`
$ $JAVA_HOME/bin/jshell
Exception in thread "main" java.lang.InternalError: Failed remote launch: com.sun.jdi.CommandLineLaunch (defaults: home=/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home, options=, main=, suspend=true, quote=", vmexec=java) -- {home=home=/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home, options=options=-classpath "/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home/lib/tools.jar:/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home/classes" -Xbootclasspath:"/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home/lib/modules/bootmodules.jimage", main=main=jdk.internal.jshell.remote.RemoteAgent 57612, suspend=suspend=true, quote=quote=", vmexec=vmexec=java}
    at jdk.jshell.JDIConnection.reportLaunchFail(JDIConnection.java:344)
    at jdk.jshell.JDIConnection.launchTarget(JDIConnection.java:310)
    at jdk.jshell.JDIConnection.open(JDIConnection.java:121)
    at jdk.jshell.JDIEnv.init(JDIEnv.java:49)
    at jdk.jshell.ExecutionControl.jdiGo(ExecutionControl.java:269)
    at jdk.jshell.ExecutionControl.launch(ExecutionControl.java:71)
    at jdk.jshell.JShell.executionControl(JShell.java:613)
    at jdk.jshell.ClassTracker$ClassInfo.getReferenceTypeOrNull(ClassTracker.java:81)
    at jdk.jshell.Unit.lambda$classesToLoad$3(Unit.java:266)
    at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1422)
    at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:591)
    at jdk.jshell.Unit.classesToLoad(Unit.java:264)
    at jdk.jshell.Eval.lambda$compileAndLoad$13(Eval.java:559)
    at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:269)
    at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1422)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:511)
    at jdk.jshell.Eval.compileAndLoad(Eval.java:560)
    at jdk.jshell.Eval.declare(Eval.java:462)
    at jdk.jshell.Eval.processMethod(Eval.java:386)
    at jdk.jshell.Eval.eval(Eval.java:128)
    at jdk.jshell.JShell.eval(JShell.java:350)
    at jdk.internal.jshell.tool.JShellTool.processCompleteSource(JShellTool.java:1540)
    at jdk.internal.jshell.tool.JShellTool.processSource(JShellTool.java:1528)
    at jdk.internal.jshell.tool.JShellTool.processSourceCatchingReset(JShellTool.java:514)
    at jdk.internal.jshell.tool.JShellTool.run(JShellTool.java:494)
    at jdk.internal.jshell.tool.JShellTool.resetState(JShellTool.java:429)
    at jdk.internal.jshell.tool.JShellTool.start(JShellTool.java:265)
    at jdk.internal.jshell.tool.JShellTool.start(JShellTool.java:260)
    at jdk.internal.jshell.tool.JShellTool.main(JShellTool.java:250)
Caused by: com.sun.jdi.connect.VMStartException: VM initialization failed for: /Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home/bin/java -classpath /Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home/lib/tools.jar:/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home/classes -Xbootclasspath:/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home/lib/modules/bootmodules.jimage -Xdebug -Xrunjdwp:transport=dt_socket,address=JMEN0520:57613,suspend=y jdk.internal.jshell.remote.RemoteAgent 57612
    at com.sun.tools.jdi.AbstractLauncher$Helper.launchAndAccept(AbstractLauncher.java:193)
    at com.sun.tools.jdi.AbstractLauncher.launch(AbstractLauncher.java:132)
    at com.sun.tools.jdi.SunCommandLineLauncher.launch(SunCommandLineLauncher.java:223)
    at jdk.jshell.JDIConnection.launchTarget(JDIConnection.java:303)
    ... 31 more

/etc/hostsにhostnameを登録して解決

[JDK-8131029] JShell: recover from VMConnection launch failure - Java Bug System

自分のマシンのホスト名を取得

$ uname -n

これを/etc/hosts127.0.0.1で追加して完了

イケた

$ $JAVA_HOME/bin/jshell
|  Welcome to JShell -- Version 9-ea
|  Type /help for help

-> /help
Type a Java language expression, statement, or declaration.
Or type one of the following commands:

/list [all|start|history|<name or id>] -- list the source you have typed
/seteditor <executable>                -- set the external editor command to use
/edit <name or id>                     -- edit a source entry referenced by name or id
/drop <name or id>                     -- delete a source entry referenced by name or id
/save [all|history|start] <file>       -- save: <none> - current source;
                                                all - source including overwritten, failed, and start-up code;
                                                history - editing history;
                                                start - default start-up definitions
/open <file>                           -- open a file as source input
/vars                                  -- list the declared variables and their values
/methods                               -- list the declared methods and their signatures
/classes                               -- list the declared classes
/imports                               -- list the imported items
/exit                                  -- exit the REPL
/reset                                 -- reset everything in the REPL
/reload [restore] [quiet]              -- reset and replay relevant history -- current or previous (restore)
/feedback <level>                      -- feedback information: off, concise, normal, verbose, default, or ?
/prompt                                -- toggle display of a prompt
/classpath <path>                      -- add a path to the classpath
/history                               -- history of what you have typed
/setstart <file>                       -- read file and set as the new start-up definitions
/help                                  -- this help message
/?                                     -- this help message
/!                                     -- re-run last snippet
/<id>                                  -- re-run snippet by id
/-<n>                                  -- re-run n-th previous snippet

Supported shortcuts include:
<tab>       -- show possible completions for the current text
Shift-<tab> -- for current method or constructor invocation, show a synopsis of the method/constructor

-> /exit
|  Goodbye