other register

Thursday, October 28, 2010

When Run (Ctrl+F11) gets stuck in Eclipse.

In Eclipse (or its derivative Spring STS 2.5.0) generically, Ctrl+F11 is Run and it is context aware. As if the cursor is in a Java class with a main method, it will run the run class; if the cursor is in a test class, it will run the test class; if the cursor is at the method line in a test class, it will run the test for this single method.

However, when a new Grails plugin is installed, or if you run "grails test-app -coverage" you will noticed from the console that: $app/web-app/WEB-INF/classes directory is deleted. And when you Ctrl+F11 to run again, it will have the following exceptions:

Class not found
at Method)
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(

Because the Default output folder is $app/web-app/WEB-INF/classes, that's why the test or run(main method for java) can't be run. 

To get your favourite Ctrl+F11 come back work for you, do the following:

1. Delete the project without deleting the content from Eclipse.
2. Import your project into Eclipse. 

/***** The following approach DOES NOT work ********/

Or better (29/10/2010)

1. Right click your project.
2. Select Grails Tools -> Refresh Dependencies

Then you will find the classes are compiled in to $app/target/classes which is the place your test or main java classes will run from.

No comments: