Is it possible to use sysout without class and main method in Eclipse IDE using Java 9?

和自甴很熟 提交于 2019-11-27 18:25:04

问题


As Java 9 introduced the concept of JShell which enables us to write code without creating a class and a method, is it possible to use this feature of Java 9 in eclipse ?


回答1:


You can use the TM Terminal to run JShell in Eclipse:

  • If necessary, install TM Terminal (contained only in some Eclipse packages)
  • Open a 'Terminal' view in Eclipse: Window > Show View > Other...: Terminal > Terminal
  • Launch a new Local Terminal
  • Run JShell, e. g. on Windows type "C:\Program Files\Java\jdk-9\bin\jshell" -v followed by Enter

Alternatively, you can use a Scrapbook Page, a built-in feature of the Eclipse Java IDE and which also works with older Java versions. You will have code completion and you can use Java classes of your project:




回答2:


If this is not a feature ask for Eclipse, a very basic stub that you can come up with is:

public static void main(String[] args) throws Exception {
     jdk.jshell.tool.JavaShellToolBuilder.builder().run();
}

When you execute this, you can further use your debug console as JShell in your IDE.

Sample screenshot:



来源:https://stackoverflow.com/questions/46805687/is-it-possible-to-use-sysout-without-class-and-main-method-in-eclipse-ide-using

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!