groovy
  1. groovy
  2. GROOVY-1395

GroovyEclipse RunAs Groovy doesn't check for a main method with the wrong kind of arguments

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.0-JSR-6
    • Fix Version/s: 1.0-JSR-6
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      1

      Description

      GroovyEclipse tries to run:

      class MyClass {
      static void main()

      { println "I am running" }

      }

      And then fails with:
      java.lang.NoSuchMethodError: main
      Exception in thread "main"

      Both the commandline and GroovyJ have a more meaningful message:
      Caught: groovy.lang.GroovyRuntimeException: This script or class could not be run.
      It should either:

      • have a main method,
      • be a class extending GroovyTestCase,
      • or implement the Runnable interface.

      GroovyJ also lets you select this class as a runnable class when
      setting up a run configuration. This class should be weeded out of
      the list of available classes.

      The main reason behind this is that EclipsePlugin is doing a partial
      check look for main and then static (and currently also incorrectly void - See Groovy-1394)
      but doesn't check for Object[] args.

        Activity

        Hide
        Paul King added a comment -

        Combined patch for Groovy-1391 through Groovy-1395.
        Will require someone to check as this is my first eclipse plugin patch.

        Show
        Paul King added a comment - Combined patch for Groovy-1391 through Groovy-1395. Will require someone to check as this is my first eclipse plugin patch.
        Hide
        Scott Hickey added a comment -

        applied patch and added the code back in to check for return type of void. As best I can tell, it appears that the Eclipse VM launcher expects void as the return type or it sends back the error. It's not apparent to me how we can work around this within the Eclipse framework, unless we launch a groovy shell which invokes main of the class specified, instead of launching the class directly. I'm neutral on whether this is good idea or not.

        It's good to be constistent with the command line behavior, but I'm not sure that I like how it wouldn't be obvious whether I'm directly invoking main() on the generated class or ask a wrapper class to instantiate and invoke it for me.

        Show
        Scott Hickey added a comment - applied patch and added the code back in to check for return type of void. As best I can tell, it appears that the Eclipse VM launcher expects void as the return type or it sends back the error. It's not apparent to me how we can work around this within the Eclipse framework, unless we launch a groovy shell which invokes main of the class specified, instead of launching the class directly. I'm neutral on whether this is good idea or not. It's good to be constistent with the command line behavior, but I'm not sure that I like how it wouldn't be obvious whether I'm directly invoking main() on the generated class or ask a wrapper class to instantiate and invoke it for me.
        Hide
        Paul King added a comment -

        Previous comment copied back to 1394 since it is mostly related to that issue. (Due to my lazy combined patch)

        Show
        Paul King added a comment - Previous comment copied back to 1394 since it is mostly related to that issue. (Due to my lazy combined patch)
        Hide
        Paul King added a comment -

        Works for me. Thanks.

        Show
        Paul King added a comment - Works for me. Thanks.

          People

          • Assignee:
            Scott Hickey
            Reporter:
            Paul King
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: