无法在Apache NetBeans IDE 10.0中初始化JShell

问题描述 投票:1回答:2

我在these steps之后在macOS Mojave(版本10.14.2)上安装了OpenJDK 11(版本11.0.2)。然后我尝试在Apache NetBeans IDE 10.0中启动JShell会话,但是我收到此错误:

|  Could not initialize JShell: Launching JShell execution engine threw: Failed remote launch: java.util.concurrent.TimeoutException @ com.sun.jdi.CommandLineLaunch (defaults: home=/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home, options=, main=, suspend=true, quote=", vmexec=java) -- {home=home=/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home, options=options=-classpath /Users/Steve/Apps/netbeans/java/modules/ext/nb-mod-jshell-probe.jar:, main=main=org.netbeans.lib.jshell.agent.AgentWorker 49866, suspend=suspend=true, quote=quote=", vmexec=vmexec=java}
|   caused by: Failed remote launch: java.util.concurrent.TimeoutException @ com.sun.jdi.CommandLineLaunch (defaults: home=/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home, options=, main=, suspend=true, quote=", vmexec=java) -- {home=home=/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home, options=options=-classpath /Users/Steve/Apps/netbeans/java/modules/ext/nb-mod-jshell-probe.jar:, main=main=org.netbeans.lib.jshell.agent.AgentWorker 49866, suspend=suspend=true, quote=quote=", vmexec=vmexec=java}
|   caused by: null

我该如何解决这个问题?

查看IDE中的Java Platform Manager,我可以看到JDK设置正确,使用Maven的简单Java SE应用程序编译并运行正常。

更新

从关于NetBeans:

Java: 11.0.2; OpenJDK 64-Bit Server VM 11.0.2+9
Runtime: OpenJDK Runtime Environment 11.0.2+9

来自插件:

Java Shell
Version: 1.2.1
Source: Apache NetBeans IDE 10.0 (Build
incubator-netbeans-release-380-on-20181217)

机器上没有安装其他JDK。

我可以在NetBeans终端中成功调用jshell:

$ jshell                                                                                                   
|  Welcome to JShell -- Version 11.0.2
|  For an introduction type: /help intro

jshell> 

打开Java Platform Shell时的IDE日志:

INFO [org.netbeans.modules.jshell.support.ShellSession]: Error in JSHell
java.util.concurrent.TimeoutException
    at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:204)
    at jdk.jshell/jdk.jshell.execution.JdiInitiator.timedVirtualMachineCreation(JdiInitiator.java:244)
    at jdk.jshell/jdk.jshell.execution.JdiInitiator.launchTarget(JdiInitiator.java:137)
Caused: java.lang.InternalError: Failed remote launch: java.util.concurrent.TimeoutException @ com.sun.jdi.CommandLineLaunch (defaults: home=/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home, options=, main=, suspend=true, quote=", vmexec=java) -- {home=home=/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home, options=options=-classpath /Users/Steve/Apps/netbeans/java/modules/ext/nb-mod-jshell-probe.jar:, main=main=org.netbeans.lib.jshell.agent.AgentWorker 50384, suspend=suspend=true, quote=quote=", vmexec=vmexec=java}
    at jdk.jshell/jdk.jshell.execution.JdiInitiator.reportLaunchFail(JdiInitiator.java:300)
    at jdk.jshell/jdk.jshell.execution.JdiInitiator.launchTarget(JdiInitiator.java:141)
    at jdk.jshell/jdk.jshell.execution.JdiInitiator.<init>(JdiInitiator.java:110)
    at org.netbeans.lib.nbjshell.LaunchJDIAgent.create(LaunchJDIAgent.java:217)
    at org.netbeans.lib.nbjshell.LaunchJDIAgent.access$000(LaunchJDIAgent.java:62)
    at org.netbeans.lib.nbjshell.LaunchJDIAgent$1.generate(LaunchJDIAgent.java:180)
    at org.netbeans.modules.jshell.tool.JShellLauncher$CaptureExecControl.generate(JShellLauncher.java:240)
    at jdk.jshell/jdk.jshell.JShell.<init>(JShell.java:126)
Caused: java.lang.IllegalStateException: Launching JShell execution engine threw: Failed remote launch: java.util.concurrent.TimeoutException @ com.sun.jdi.CommandLineLaunch (defaults: home=/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home, options=, main=, suspend=true, quote=", vmexec=java) -- {home=home=/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home, options=options=-classpath /Users/Steve/Apps/netbeans/java/modules/ext/nb-mod-jshell-probe.jar:, main=main=org.netbeans.lib.jshell.agent.AgentWorker 50384, suspend=suspend=true, quote=quote=", vmexec=vmexec=java}
    at jdk.jshell/jdk.jshell.JShell.<init>(JShell.java:139)
    at jdk.jshell/jdk.jshell.JShell$Builder.build(JShell.java:405)
    at org.netbeans.modules.jshell.tool.JShellLauncher.createJShellInstance(JShellLauncher.java:258)
    at org.netbeans.modules.jshell.support.ShellSession$Launcher.createJShellInstance(ShellSession.java:624)
    at org.netbeans.modules.jshell.tool.JShellTool.resetState(JShellTool.java:745)
    at org.netbeans.modules.jshell.tool.JShellLauncher.resetState(JShellLauncher.java:207)
    at org.netbeans.modules.jshell.tool.JShellLauncher.ensureLive(JShellLauncher.java:195)
    at org.netbeans.modules.jshell.tool.JShellLauncher.getJShell(JShellLauncher.java:201)
    at org.netbeans.modules.jshell.support.ShellSession.initJShell(ShellSession.java:829)
    at org.netbeans.modules.jshell.support.ShellSession.getJShell(ShellSession.java:309)
[catch] at org.netbeans.modules.jshell.support.ShellSession.lambda$null$2(ShellSession.java:514)
    at org.netbeans.modules.jshell.model.ConsoleModel$ModelAccImpl.execute(ConsoleModel.java:1104)
    at org.netbeans.modules.jshell.support.ShellSession.lambda$start$3(ShellSession.java:510)
    at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1418)
    at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45)
    at org.openide.util.lookup.Lookups.executeWith(Lookups.java:278)
    at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2033)
netbeans java-11 jshell
2个回答
2
投票

这不是一个真正的答案 - 它更多是对更多信息的要求 - 但我的问题和建议不符合评论:

  • 这对我在NetBeans 10.0上使用OpenJDK 11.0.2起作用,尽管我在Windows 10上运行。
  • 在NetBeans中执行“帮助”>“关于”时,屏幕上显示的Java和运行时的值是什么?显示的JDK不一定与Java Platform Manager中显示的相同: helpAbout
  • 检查是否已安装JShell插件: 选择工具>插件,然后单击已安装选项卡。 选中Show Details复选框,然后单击Name列标题(如有必要),按字母顺序对条目进行排序。 向下滚动并确认您可以选择名为Java Shell的条目。它的缺席会解释你的问题: installedPlugins
  • 从您的计算机中删除所有未使用/不需要的JDK安装。由于您已经安装了JDK 11.0.2,因此您可能不希望或不需要计算机上的任何早期版本(除非其中一个版本用于运行NetBeans,如上所述的“帮助”>“关于”屏幕中所示)。
  • 验证您是否可以使用OpenJDK 11.0.2从终端调用jshell(以确定jshell问题是否仅限于NetBeans)。

最后,作为完整性检查,打开NetBeans日志(“查看”>“IDE日志”)并查看与jshell相关的任何问题。如果找到任何内容,请更新您的问题我日志中的这些行包含“jshell”,希望你看到类似的东西:

WARNING [org.netbeans.core.modules]: the modules [org.netbeans.modules.java.hints, org.netbeans.modules.jshell.support, org.netbeans.modules.maven.hints, org.netbeans.modules.maven.j2ee, org.netbeans.modules.web.beans] use org.netbeans.modules.java.hints.legacy.spi which is deprecated: Use Java Hints SPI (org.netbeans.spi.java.hints) instead.
    org.netbeans.lib.nbjshell [1.6 incubator-netbeans-linux-934-on-20181203]
    org.netbeans.modules.jshell.support [1.4.0.25.55.17.1.4 incubator-netbeans-linux-934-on-20181203]
    org.netbeans.lib.nbjshell9 [1.3 incubator-netbeans-linux-934-on-20181203]
    --add-opens=jdk.jshell/jdk.jshell=ALL-UNNAMED
    --add-modules=jdk.jshell
WARNING [org.openide.loaders]: Should override getLookup() in class org.netbeans.modules.jshell.env.JShellDataObject, e.g.: [MultiDataObject.this.]getCookieSet().getLookup()
WARNING [org.openide.filesystems.Ordering]: Found same position 20,000 for both Separator-before-shell-reset.instance and jshell-reset.shadow
INFO [org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater]: Indexing of: C:\Users\johndoe\AppData\Local\NetBeans\Cache\dev\jshell\junk took: 65 ms (New or modified files: 0, Deleted files: 0) [Adding listeners took: 0 ms]
WARNING [org.openide.filesystems.Ordering]: Not all children in / marked with the position attribute: [org-netbeans-modules-lsp-client-bindings-CompletionProviderImpl.instance], but some are: [org-netbeans-modules-jshell-editor-HistoryCompletionProvider.instance, org-netbeans-modules-jshell-editor-CommandCompletionProvider.instance]
WARNING [org.openide.filesystems.Ordering]: Not all children in / marked with the position attribute: [org-netbeans-modules-lsp-client-bindings-CompletionProviderImpl.instance], but some are: [org-netbeans-modules-parsing-ui-WaitScanFinishedCompletionProvider.instance, org-netbeans-modules-editor-java-JavaCompletionProvider.instance, org-netbeans-modules-jshell-editor-HistoryCompletionProvider.instance, org-netbeans-modules-java-editor-javadoc-JavadocCompletionProvider.instance, org-netbeans-lib-editor-codetemplates-CodeTemplateCompletionProvider.instance, org-netbeans-modules-j2ee-persistence-editor-completion-JPACodeCompletionProvider.instance, org-netbeans-modules-websvc-editor-completion-WSCompletionProvider.instance, org-netbeans-modules-spellchecker-completion-WordCompletion.instance]
WARNING [org.netbeans.modules.parsing.impl.TaskProcessor]: ParserManager.parse called in AWT event thread by: org.netbeans.modules.jshell.parsing.ConsoleEmbeddingProvider.getEmbeddings(ConsoleEmbeddingProvider.java:62)

0
投票

我也无法在一个项目上执行JavaShell,新的Netbeans在几乎所有不能编译简单java或maven项目的东西中被破坏,但是为了测试一个没有文档的大型库我必须解决这个问题。

作为一种解决方法,我执行了这些步骤(与您的NB / JRE配置相同):

  1. 从菜单工具> Open Java Platform Shell打开Platform Shell,而不是直接从项目执行它
  2. 将我需要的库导入类路径。

举个例子。

[1]-> /classpath C:\Users\brazorv\Documents\NetBeansProjects\JavaTest\dist\JavaTest.jar
|  Path 'C:\Users\brazorv\Documents\NetBeansProjects\JavaTest\dist\JavaTest.jar' added to classpath
[1]-> import javatest.JavaTest;
[2]-> JavaTest jt = new JavaTest();
|  jt ==> javatest.JavaTest@2de8284b
[3]-> jt.main(new String[]{});
[4]-> (my method just prints something on the terminal  output)

而已。我希望这是有帮助的。

© www.soinside.com 2019 - 2024. All rights reserved.