Eclipse Plugin for Quick Java Code Testing

I wonder if there is a plugin for Eclipse that can execute some kind of java expression?

For example, I want to find the correct SimpleDateFormat template, and I could create a new class in which I then initialized several formatters, and after compiling and executing I will see the result, but instead I want to be able to write these formatting in this plugin and see their result after execution without a new class.

thanks

+6
java eclipse eclipse-plugin
source share
6 answers

I am using the scrapbook page.

To create it, go to File -> New -> Other -> Java -> Java Run/Debug -> Scrapbook Page . Enter statements, for example.

 String text = new java.text.SimpleDateFormat("yyyy-MM-dd").format(new java.util.Date()); System.out.println(text); 

Run it by selecting the text ( Ctrl+A ) and then Ctrl+U

The only thing I don't like is that it does not allow import applications. You must either enter the full name of the class as described above, or explicitly go to the Set imports menu and add the classes you want to import.

+13
source share

You can use the scrapbook page - just select New-> Other-> Java Run / Debug

On the scrapbook page, you can simply write the code, then select parts of it and select “Screen”, “View” or “Run” in the context menu.

However, this is actually not very convenient for working with class libraries, because you need to use fully qualified class names.

+3
source share

When you paused a running application in debug mode, you can select any piece of code and execute it to give you a quick, albeit slightly inconvenient way to try out various SimpleDateFormat calls. All you need is one mock class with the main method and a breakpoint in it.

+1
source share

Beanshell lets you do this. I don’t know if there is an eclipse plugin, but you can easily run it offline or from within eclipse in the usual way so that it has access to your project class.

Alternatively, when you are working in debug mode, you can evaluate arbitrary expressions on the Display tab.

+1
source share

I started with scrapBook , but after a while I realized that it was slowing down. Mostly because you must use fully qualified class names, such as java.util.Map, only invoke java.lang imports. *. There is support for content, but nothing like "the file cannot be resolved - import it"

As a result, it is better to have a class with the Main method and make it there. Because you get all the Java Editor support for eclipse. Alternatively, use TestNG or JUnit to run one of your testing methods. It’s better for me for this purpose than in the main class. For this purpose, I never used execution in debug mode. I use it only to print out variable values.

The second option is an eclipse-shell plugin. But this is the same problem. This is not so useful for supporting the Java IDE editor. I believe that this is the reason why these two options are used little. One tries, but realizes that this makes no sense without the support of a Java editor.

0
source share

You can always write the Main method in any class and run it.

But if you need it, you should familiarize yourself with

Eclipse plugin development

Interpreter

-one
source share

All Articles