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 29934 - Cannot use JavaProcessExecutor for classes w/o main method
Summary: Cannot use JavaProcessExecutor for classes w/o main method
Status: VERIFIED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Unsupported (show other bugs)
Version: 3.x
Hardware: All All
: P2 blocker (vote)
Assignee: Tomas Hurka
URL: http://www.netbeans.org/servlets/Read...
Keywords: REGRESSION
Depends on: 22813
Blocks:
  Show dependency tree
 
Reported: 2003-01-10 07:10 UTC by Jesse Glick
Modified: 2007-09-26 09:14 UTC (History)
0 users

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 2003-01-10 07:10:13 UTC
Observed in [dev jan 09], but reported for
earlier, and probably broken since 3.4.

If you try to create a customized
JavaProcessExecutor ("External Execution") to
execute a special kind of class with a wrapper,
the executor prevents you from doing so (for no
apparent reason).

E.g. to reproduce:

In sampledir, create a file Wrapper.java:

public class Wrapper {
    public static void main(String[] args) throws
Exception {
        String clazz = args[0];
        Class c = Class.forName(clazz);
        Runnable r = (Runnable)c.newInstance();
        r.run();
        r.run();
    }
}

and a file Foo.java:

public class Foo implements Runnable {
    public void run() {
        System.out.println("Ran Foo...");
    }
}

Compile them.

Now create a new External Execution type, called
Wrap Exec. Set its External Process:

{java.home}{/}bin{/}java Wrapper -cp
{filesystems}{:}{classpath} {classname}

Set executor for Foo to Wrap Exec. Select Foo,
click Execute. You get:

Class Foo has no main method. Configure / Cancel

and on console:

INFORMATIONAL *********** Exception occurred
************ at Fri Jan 10 02:03:03 EST 2003
Annotation: Class Foo has no main method.
java.io.IOException
	at
org.netbeans.modules.java.JavaExecSupport.isExecutable(JavaExecSupport.java:106)
	at
org.netbeans.modules.java.JavaProcessExecutor.execute(JavaProcessExecutor.java:103)
[....]

Whereas it should print to the Output Window:

Ran Foo...
Ran Foo...

This is a regression in JavaProcessExecutor.java:

revision 1.3
date: 2002/05/03 12:42:31;  author: thurka; 
state: Exp;  lines: +10 -0
bugfix #22813, JavaProcessExecutor and
JavaThreadExecutor were modified to check that
they can execute selected file

Now #22813, as far as I can tell, was referring to
JavaThreadExecutor, for which the executor does
indeed need to check for a main method - it is
going to call it, and this is not configurable.
But for JPE, you cannot know what the external
process will want to check. In fact running a
class with no main method using the Java launcher
is harmless; you get a reasonable message:

Exception in thread "main"
java.lang.NoSuchMethodError: main

Doesn't offer to let you configure the executor,
it is true, but so what; you can still do that if
that is what you actually wanted.

Cf. nbusers.
Comment 1 Jesse Glick 2003-01-10 07:15:49 UTC
Probable workaround (untried, just off the top of my head):

Make sure the directory $userdir/system/Templates/Services/Executor/
exists.

Create a file in it, PlainProcessExecutor.settings:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE settings PUBLIC "-//NetBeans//DTD Session settings 1.0//EN"
"http://www.netbeans.org/dtds/sessionsettings-1_0.dtd">
<settings version="1.0">
    <instanceof class="org.openide.ServiceType"/>
    <instanceof class="org.openide.execution.Executor"/>
    <instance class="org.openide.execution.ProcessExecutor"/>
</settings>

Restart NB. Open Options dialog. Expand Templates -> Services ->
Execution Types -> (something), whichever the new one is - you will be
able to tell since it will have no {assertEnabled} in the arguments.
Click it and set Template to True in the prop sheet. Rename it if
necessary to make it distinctive. Now use that as the template for new
external execution services; it should not have the undesirable behavior.
Comment 2 Tomas Hurka 2003-03-07 15:22:04 UTC
You are right. This is regression -> raising priority. I will remove check in JavaProcessExecutor. 
Comment 3 Tomas Hurka 2003-03-08 17:52:47 UTC
Fixed in trunk and release35 branch. 
Comment 4 Jan Becicka 2003-03-10 15:05:26 UTC
VERIFIED