Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-3749

Cannot have a script with a main method as the starting point

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.7-beta-1
    • 1.7-beta-2, 1.6.6
    • Compiler
    • None
    • Groovy Version: 1.7-beta-2-SNAPSHOT JVM: 1.5.0_06 (Windows XP)

    Description

      Can a groovy script not provide its main() method?

      Case 1: If I run the following script, nothing happens:

      static main(args) {
          println "Roshan"
      }
      

      Doing a javap on the generated class, I see it now has duplicate definitions of main(), as:

      public static void main(java.lang.String[]); // groovy generated
      public static java.lang.Object main(java.lang.String[]); // one provided in the script
      

      In the above script nothing is happening because groovy invokes its own main(), which is effectively empty here.

      Case 2: If I change the script to:

      static void main(args) {
          println "Roshan"
      }
      

      then it fails saying

      Repetitive method name/signature for method 'void main(java.lang.Object)' in class 'Try'.
      

      So, there is no way I can write a script that has main() as the starting point.

      First case produces an invalid class and second case also does not allow the user to provide his own main() starting point.

      Attachments

        Activity

          People

            roshandawrani Roshan Dawrani
            roshandawrani Roshan Dawrani
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: