Tag Archives: eclipse

How to edit React jsx scripts in Eclipse?

I was about to use React in a new project when I hit a development PITA. How do you edit the JSX scripts within a page using Eclipse?

In React, you can use JSX files or JSX script embedded in the page. The JSX transformer converts these to standard JavaScript at compile or in the browser.
Note: Embedding JSX scripts in a page is most likely a very bad thing to do. Maybe justified for learning React, demos, or quick examples.

Eclipse allows the use of shortcut key bindings for various views and content types.

From the React docs, below is a sample jsx script. When this is embedded in an HTML file within Eclipse, such as index.html, there is no way to edit the script using the normal Editing key bindings. Even indentation of highlighted lines fails. Weird, I even tried to create a new key binding for TAB or ctrl+i, to no avail.

<script type="text/jsx">
	var HelloWorld = React.createClass({
	  render: function() {
		return (
			Hello, <input type="text" placeholder="Your name here" />!
			It is {this.props.date.toTimeString()}

	setInterval(function() {
		<HelloWorld date={new Date()} />,
	}, 500);

If I discover how to get around this, I’ll post here. Of course, you can put your jsx code into an external js file, that Eclipse has no problem with.

Mar 1, 2016: Working on a new React/Redux app. Now in Eclipse, when editing js files and add a line by entering return at the end of a line, Eclipse adds + ” at the new line break. Oh veah. Creating runtime errors.


Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.

Continuous testing with Infinitest

With Infinitest every time you make a change in your code, the JUnit tests will be executed. How cool is that? Infinitest will run in IntelliJ or Eclipse.

I wrote a more generic post on CT that forks this post: Continuous Testing while developing, CDT?.

I tried it in a very small Groovy project, and it worked. Of course, Groovy compiles to Java, but in an IDE things get complicated.

Unfortunately on a large Java project it did not seem to work, and the web site does not have enough information to determine what the issue is. For example, the status line is showing that it is running a test (unrelated to the recently changed code) and it shows “(400 remaining)”, remaining what?

Whether this plug-in works does not negate the concept of Continuous Testing as discussed below.

I installed the plugin using the update site. Made no configuration changes. Then I changed my code, and nothing happened, just a status at the bottom that one test case ran. In fact, I changed the Unit test code to force a failure.

Then I noticed that Eclipse’ Problems view had red ‘x’. Hmmm, I didn’t make any compile related changes. Opening the Problems view showed the actual test failure. Ah, now I get it. The status bar is just like the JUnit status, red or green.

I thought the plugin would reuse the JUnit view in Eclipse. It doesn’t, instead it adds any failures to the Problems view. Thinking about it, that is the correct approach. When your coding the only distraction you need is to know if a change to code broke something, comparable to a compile just getting compile errors.

Bringing up a new view, especially the JUnit view would be heavy weight. When you focus on testing then the full JUnit view is more useful. But maybe this should be a configuration choice?

Anyway, the workflow is just code as usual. The status message at bottom of the IDE will be Green or Red depending on the test run. When red, the Problems view will show the test failure. Unfortunately clicking on the error line will not bring you to the failing test, but this could be that this is a Groovy Project.

Continuous Testing
We don’t edit code then invoke a compile step anymore. Our IDEs do that automatically. Then why have to invoke our unit tests manually? This “Continuous Testing” (CT) approach enables a smoother Test-Driven Development (TDD), maintenance, or refactoring, work flow.

Is there any evidence of this? Some papers on CT are found here.

If you search for the term ‘continuous testing’ there is not much. Usually it appears in the context of Continuous Integration servers. Perhaps its time to make CT more visible so that it’s more available as a development practice.

Great videos on the CT as implemented in Mighty-Moose, a product for Microsoft Visual Studio, are found at continuoustests.
Mighty Moose Demo, a CT product for Visual-Studio.

Mentioning this to any developer will give you immediate “buts”: But my tests take too long; it would be distracting; I change code constantly;…… I sometimes think developers are driven by a little motor in them, but … but … but … buuuut.

The only thing I see in Infinitest to address these concerns is the use of a filters configuration file. You can add multiple regex to avoid tests that you don’t want to run all the time.

I’d like the opposite too. The ability to easily define what I am interested in testing, inclusion filters. On a large code base you may be concentrating on a few packages, so it should be easy to just add those to a filter without having to drag out the “Mastering Regular Expressions” book.

Though Infinitest is good, why isn’t running a configuration on configured type of changes supported in Eclipse? Is there is a direct way to invoke the JUnit plugin via adding a new custom “builder” to Eclipse? A builder in Eclipse is triggered by resource changes. So, on source code change this builder would have to run an associated ‘JUnit run configuration’.

May 1, 2014: While looking at the Infinitest source I noticed they use AssertJ. Another great library. So many cool things. So why is code bug ridden? Just joking.
May 6, 2014: Tried Infinitest in a larger project. Did not work.

Tested on
Eclipse Kepler Service Release 2
Groovy Plugin 2.9.0
Groovy compiler 2.2
Infinitest 5.1.110
Windows 7


Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.

Unable to dock detached Eclipse Console window

When the Eclipse IDE ‘breaks’ it seems to be unfixable. Like right now. I detached the Console view window via dragging onto another monitor. Done with it. Now I can’t dock the Console again inside the Java Perspective.

The top left widget just shows a ‘close’ action. I tried closing projects, restarting Eclipse with “-clean”, and of course doing a search to see if this has been addressed by someone before. Sometimes it will go away and another docked Console will be used. But then it pops up again in float mode, and duplicating the output in the already docked Console, i.e., now two Consoles are showing the same thing.

Reinstall Eclipse again????? Arrrrrrrrrrrrrr. Let me reboot Windoze first.

I rebooted PC, rearranged Eclipse on the multi-monitor location, and the issue has not returned.


  1. The issue started again. I looked in the JUnit run configuration’s common tab for the test causing this. The “Launch in background” setting was checked. hmmm.
  2. Still not working. Second console window popup still appearing.
  3. Now trying the suggestion found here.
  4. Doh!!!!! I was dragging the window via the title bar. You have to drag via the tab title.

I guess working in different environment made me lose my muscle memory gesture.
Number 3 above fixed the popup reappearing.


  • Eclipse 4.3 (Kepler)
  • Windows 7 Professional 64bit
  • Java 1.6 and 1.7
  • Dual monitor
  • UltraMon utility

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.

GUI piping instead of screen shots

Currently I have to share info via capturing screen shots of various tools. An example of where this is required is in Eclipse’s Java developers environment.

The Eclipse IDE via the various added plugins and features captures a lot of metadata about a project and its various assets. For example, in the outline view you can see various listings with applied filters. Now try to share that in an email or document. You have to take a snap shot of the screen. This is not a very practical example, it’s just to show the issue. This issue comes in various other plugins like Team providers. Note, I’m not singling out Eclipse on this; all tools and applications have this problem.

While screenshots can convey the original purpose of sharing a particular view of data, they are very difficult to reuse in diverse ways. For example, we may want to sort or filter a listing of data. Or we we may want to reuse that data with external reporting or metric applications. With a GUI screen shot this is not possible.

Graphical tools should allow piping of information. As in Unix piping, a tool should allow re purposing of its generated data. This is not just a developers geeky need; many times error pop ups and other types of displays do not allow the end user to copy the actual ASCII textual information.

There are many ways of doing this. At root, the two options are textual piping, as used in *nix systems, and object piping, as used in PowerShell.

The ideal solution would allow a drag&drop functionality. This is already used in many apps via OS or application level support. For example, right click on the browser and you can copy stuff. Yet, even in the browser scenario, the data result is not semantic (based on the information context), it’s just text or via the contextual menu a set of standard objects.

One possibility is that a drag&drop sets up a pipe line and a standard markup of the data is transferred.


Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.

In Eclipse, search for all text in current file?

Many good editors, especially graphical based ones, allow the user to search the current file for all occurrences of a text string. Some will offer to highlight the text, others will use a search output window to show the search results. Note that this is automatically performed for the currently edited file. This is required to make an unimpeded grasp of a code base, to keep up with the thought process. Opening up dialogs and clicking and clacking breaks the flow.

Eclipse can’t do this!
Yup, its been around so long, and it still can’t do this simple thing. I could be missing something, an obscure magical key binding, a buried preference, but I’ve looked.

Current Options
Lets be more accurate. The Eclipse IDE has powerful search capability and it could find all text within a file and put the results into the search result window. However, invoking this for ONLY the current edit window is a user experience failure. What are the options? Using the default key bindings:

  1. Ctrl-H: brings up a modal dialog window that has a plethora of options, but germane to this blog rant, nothing in the file path input.
  2. Ctrl-F: Another window, which is the above window lite. At least it is targeted for the current file. But, it won’t show all matches; turning off incremental just turns off searching per each keystroke into the text input field.
  3. Alt-F: This one will find all occurrences of text in the current file. Awesome!!! But, only for the currently highlighted text string in the editor. Sheesh, first I have to find it in order to find it. Que “The Three Stooges” theme song.

Note: Alt-F is not a default Eclipse key mapping. To map it bind the “Find Text in File” command to Alt+F in ‘In Windows’ at Category ‘Search’ for User ‘CU’.

What To Do?
Enhance Eclipse so that when the user does an Alt-F keystroke, check if text is highlighted in the current edit window. If there is, do the above. It there is no highlighted text, then put up a version of the simple search dialog that Ctrl-F would have created, but this dialog would have a new “All Occurrences” select box already checked. That was easy!

I would even do it myself except, learning the Eclipse internals and all associated devadministrivia would be a career in itself. So in the meantime lets just warm up our fingers in the morning cause they’ll have to be limber; a lot of dialogs will have to open and close just to find what your after.


Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.

Eclipse IDE 4.2 UI is austere

Some people don’t like the new Eclipse Juno release default L&F. Its kind of underwhelming.

I don’t think it is so bad. For use on a large monitor (and what company tortures their developers with small monitors?) the earlier UI is much better. On laptops and smaller monitors, the new UI makes sense.

If you rather have the 3.x appearance go into Window -> Preferences -> General -> Appearance. There you will find a drop down to select the Theme. When I installed the new version the default was “Windows 7″. Change to “Classic”, then restart Eclipse.

The result should be more like Eclipse 3.8.

What is worse is the the changes to UI behavior. For example, I tried to put the Outline view on top of the Navigator view. The UI would attempt to arrange them every which way but stacked. Finally on a guess I dragged a view to the actual tab area, not the view’s work area (as in version 3.8) and it worked.

Further Reading

Eclipse 3.8 vs 4.2


Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.

Groovy-Eclipse, compile and run are using different classloaders?

In an Eclipse Groovy project, the order of compilation is causing Groovy classloader conflicts.

I just manually deleted the compiled Groovy classes, then ran the app. Works. Now I rerun still works. Now add a simple blank line to one of the sources and run. It died. Manually delete the output class files, works again. 🙁

Strange I don’t have “rebuild automatically” turned on. Also strange, in the project properties, for builders, only the Java builder is listed.

The console output when I get the error:

Caught: groovy.lang.MissingMethodException: No signature of method: static main.SimpleServerSupport.keepAlive() is applicable for argument types: (main.QuestionServer, java.lang.Long) values: [main.QuestionServer@b32ed4, 60000] Possible solutions: keepAlive(main.QuestionServer, java.lang.Long)

The following classes appear as argument class and as parameter class, but are defined by different class loader:
main.QuestionServer (defined by ‘groovy.lang.GroovyClassLoader$InnerLoader@16921fd’ and ‘org.codehaus.groovy.tools.RootLoader@42e816’)

If one of the method suggestions matches the method you wanted to call,
then check your class loader setup.
at main.QuestionServer.main(QuestionServer.groovy:72)

Haven’t solved this yet. I can’t find any reference to something like it. Maybe I just have a config issue?

I now remember that the plugin adds hooks into the Java compiler. So is the compiler used different when you run the app with “run as Groovy script” then when Java builder executes, that is what the Classloader names would suggest? But, that makes no sense, since at run time, the classloader hierarchy has nothing to do with the compile, or does it, since Groovy precompiles at runtime?

Yes, I uninstalled the Groovy feature and reinstalled.
Running the same program (script) at the command line is fine.

Todo: Post some code that exhibits the issue. The current code is still at the “throw at wall and see what sticks” stage.


  • 20110328T2010-5: Solved it. I moved a method from a support class, into the main SimpleServer class. This method was using an Executor.newScheduledThreadPool(1) to start a thread to limit the server’s lifetime, it also did a little console spinner to show that there is something running. I don’t see how that is related to classloaders.

Windows 7 64bit Professional
Eclipse Helios Service Release 2
Groovy-Eclipse Feature 2.1.3.xx-20110317-1200-e36

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.

Java Dev Using Embedded Groovy Console in Eclipse

In development, simple but powerful tools to get at the essence of a code source in order to understand, test, and extend it is essential. This is even more important in Test Driven Development (TDD). Eclipse’s Java Debugger is for most situations, powerful enough. Eclipse has an Expressions View available in the debug perspective to execute snippets of code. The Java Development Toolkit (JDT) also has a Scrapbook facility that allows the creation, storage, and running of experimental code. And, of course, all the other features of the debugger are excellent.

However, when you need it, it’s possible to embed a script engine and have new ways of analyzing and developing code. In listing 1, an app shows the use of the ConsoleWaiter class. When the code executes the waiter.run() at line 43, it opens the Groovy Console which allows the use Groovy shell scripting in a GUI frame, see figure 1. When the console is closed the app continues executing.

Listing 1
* File: ExampleApp2.java
* @author jbetancourt
* Date: 20101213T1718-5
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

* @author jbetancourt
public class ExampleApp2 {
   static public String greeting = "Hello world!";
   private static final List<String> nodes;

   static {
        nodes = new

   private String title = "Example 2";

   public String getTitle(){
      return title;

   * @param args command line args
   public static void main(String[] args) {
      ExampleApp2 app = new ExampleApp2();

      ConsoleWaiter waiter = new ConsoleWaiter(app);

      waiter.setVar("greet", greeting);
      waiter.setVar("nodes", nodes);
      waiter.setVar("title", app.getTitle());

screen capture of Groovy console
Console screen capture, click to view
Another screen capture, click to view

This is awesome. In one project I had to examine the contents of a Properties object. Did it have an “email” value? I was stumped when using the Eclipse debugger, it did not show all entries in the Map, at the end was “…”. Sure, I could use the Expressions window, but with the Console I could not only do a get(key), but iterate using Groovy style closures and much more.

The magic that enables this is the ConsoleWaiter.groovy class shown below in listing 2 that was written by John Green. Since a Groovy script is a Java class underneath, in Eclipse you can call Groovy from Java easily (some compiler magic).

Listing 2
 * File:  ConsoleWaiter.groovy

import groovy.lang.Binding;
import groovy.ui.Console;

 * Provides a wrapper for the console.
 * Based on source by John Green
 * Adapted from:  http://www.oehive.org/files/ConsoleWaiter.groovy
 * Released under the Eclipse Public License
 * http://www.eclipse.org/legal/epl-v10.html
 * I added methods to allow use from Java.
 * The run() method launches the console and causes this thread
 * to sleep until the console's window is closed.
 * Allows easy interaction with the objects alive at a given
 * point in an application's execution, like in a debugger
 * session.
 * Example 1:
<pre> * new ConsoleWaiter().run()

 * Example 2:
<pre> * def waiter = new ConsoleWaiter()
 * waiter.console.setVariable("node", node)
 * waiter.run()
class ConsoleWaiter {
 Console console
 Object source
 boolean done = false;

 /** */
 public ConsoleWaiter(Console inConsole){
    this.console = inConsole

 /** */
 public ConsoleWaiter(Object source){
    console =
    new Console(getClass().classLoader,
    new Binding())
    this.source = source
    console.setVariable("source", source)

 /** */
 public void setVar(String key, Object value){
    console.setVariable(key, value)

 /** 	 */
 public void setVar(String key, List values){
    console.setVariable(key, values)

 /** 	 */
 public void setVar(String key, Object[] values){
    console.setVariable(key, values)

 /** 	 */
 public void run() {
    // I'm a little surprised that this exit() can be private.
    console.frame.windowClosing = this.&amp;exit
    console.frame.windowClosed = this.&amp;exit
    while (!done) {
       sleep 1000

 /** 	 */
 public boolean isDone(){
    return done;

 /** 	 */
 public void exit(EventObject evt = null) {
    done = true

 /** 	 */
 public Console getConsole(){
    return console;

Eclipse Integration

The disadvantage of this approach is that you have to put extraneous code inside the tests or target class. Not only is this tedious and slow, what if code is accidentally deployed like this? A better approach is to just set a breakpoint in the code, and then have the ability to open a script console at that breakpoint, in the Java Stack Frame, that has access to the execution context and classpath. Is there an Eclipse add-in that does this? If not, there should be.


Shown was a simple example of embedding a Groovy console in Java code to allow scripting. Of course, this is not a new idea. It was even mentioned in an older JVM scripting language, Beanshell. Note that it is possible to instead of using a GUI console, to use the Groovy shell, InteractiveShell class. In the reading list below this approach is taken to allow remote scripting of a server hosted application.


  • Oct 10, 2011:
    Interesting tool that could be relevant: YouDebug.
  • March 20, 2012: Not exactly same scenario, but the concept of an embedded script console is found in many products. Jenkins CI Server has one and it uses Groovy. Jenkins Script Console

Further reading

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.