This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 152096 - Difficult to set a Groovy class as main class in a j2seproject
Summary: Difficult to set a Groovy class as main class in a j2seproject
Status: RESOLVED FIXED
Alias: None
Product: groovy
Classification: Unclassified
Component: Code (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker (vote)
Assignee: Petr Hejl
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-11-01 17:19 UTC by Jesse Glick
Modified: 2009-02-19 20:52 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Glick 2008-11-01 17:19:39 UTC
20081028. After making a j2seproject and adding an empty *.groovy class to it, I press F6 - and am greeted with a dialog
to select a main class with no entries.

If I add a class definition with a public static void main(String[]) method to it, I can select the Groovy class as
main, and then delete the method afterwards.

This is silly because I can have a Groovy class containing just e.g.

---%<---
println "hello"
---%<---

and run it. Ideally I could set any Groovy class as main if it had any statements in it outside of a class definition.
Comment 1 Petr Hejl 2008-11-18 16:36:05 UTC

*** This issue has been marked as a duplicate of 150028 ***
Comment 2 Jesse Glick 2008-11-18 18:30:08 UTC
Doesn't really seem to be a duplicate to me. This issue is about the main class chooser. Issue #150028 is about the
context menu of *.groovy files. I think they are independent problems.
Comment 3 _ wadechandler 2008-11-20 23:07:24 UTC
Yes, I don't see this as a duplicate either. Seems two completely separate issues. In the other the editor needs to know
if the file may be run, and if it can run it from the context menu. Here the project support for setting the main class
needs to use that same logic to weed out whether or not it can be a main class. Now, running a main method versus
running external groovy script...how is that handled? Does the groovy compiler compile those external statements into a
main method or something else? If not a main method then those can't be run the same way a main method can by the JVM,
well by the Java launcher anyways, the VM can be instructed to run any static method through native library calls, but
strictly from the Java project support this needs to be known it seems.
Comment 4 Petr Hejl 2008-11-21 21:18:44 UTC
Mea culpa. We should track it as separate issue.
Comment 5 Petr Hejl 2008-11-24 10:58:25 UTC
I'm afraid I don't fully understand (or the issue was fixed already).

What I'm testing:
1) create Java application without main class
2) create new Groovy class, for example x.NewGroovyClass
3) put public static void main(String[] args){} into it
4) class is offered as main (expected)

5) create new Groovy class, for example x.NewGroovyClass2
6) put println "Hello" outside of the class
7) change the generated class def NewGroovyClass2 to NewGroovyClass2X (otherwise combination of NewGroovyClass2 defined
in NewGroovyClass2.groovy file with statements outside of the class is not a valid groovy source)
8) class is offered as main (expected)

9) create new Groovy class, for example x.NewGroovyClass3
10) delete everything in it
11) put println "Hello" to file
12) class is offered as main (expected)
Comment 6 Jesse Glick 2008-11-24 18:18:48 UTC
Seems to work in 081120 so I guess it was fixed sometime recently?