On 10/1/25 21:41, Kenneth Fogel wrote:
> I am using NB 27, Java 25, and Maven 3.9.11. I have a simple application with 
> two files. One is in the compact source file format meaning there is only a 
> method in the file with a signature of void main(). In this main the other 
> class is instantiated and called upon. I am using the pom file generated by 
> NetBeans and both files are in the same package. Compact source files do not 
> allow a package statement, I am verifying this on the Amber mailing list, but 
> they can have an import statement.
right. To my knowledge (and based on previous testing) compact java files have 
no concept of a package,
imported dependencies can have a package of course.

When used inside a project, like in your case with maven, they can be in the 
root package and most things
will continue to work.

The reason for that is fairly simple: they compile into a regular class file 
with synthetic class declaration etc. Tools
which can run java classes usually also can run "compact" java files once they 
are compiled - since they look
the same.

You can also see this if you run a dev build of NB and switch the navigator to 
"Trees". Its just a final class
with class name = file name.

But keep in mind running a class in a project will use the build tool to run 
it, it does not use the
"java" launcher, like it would if you run project-less files from the favorites 
window.

>  If I use Run from the project context menu and the pom file has or does not 
> have <defaultGoal> it works. If I use Run Maven -> Other Goals and use 
> compile exec:java or have these in the <defaultGoal> I get this error:
> java.lang.Exception: The specified mainClass doesn't contain a main method 
> with appropriate signature.
> Both Run and Run Maven use Maven but with a slightly different command line. 
> I'd expect my example to work with both, not only with Run.
> Is this an NB issue or a Maven issue?

not completely sure what you are trying to do but I did the following:

1) used a dev build of NB so that I can use the new goal copy button (#8818)
2) created a maven project, removed the hello world class
3) put two compact java files (Compact1 and Compact2) into the main package, 
one prints hello1, the other prints hello2
4) opened project actions, copied the "run file via main" action twice
5) set the main class property of one of the copied actions to Compact1, the 
other Compact2

now i had two actions which could run 1 or 2 in the context menu, additionally 
to the
regular context sensitive single-file (shfit+F6) run action and the project run 
(F6) action (which both worked too).


nbactions.xml would look like this:


<actions>
    <action>
        <actionName>CUSTOM-run via main 1</actionName>
        <displayName>run compact 1</displayName>
        <packagings>
            <packaging>*</packaging>
        </packagings>
        <goals>
            <goal>process-classes</goal>
            <goal>org.codehaus.mojo:exec-maven-plugin:3.5.1:exec</goal>
        </goals>
        <properties>
            <exec.vmArgs></exec.vmArgs>
            <exec.args>${exec.vmArgs} -classpath %classpath ${exec.mainClass} 
${exec.appArgs}</exec.args>
            <exec.mainClass>Compact1</exec.mainClass>
            <exec.executable>java</exec.executable>
            <exec.classpathScope>${classPathScope}</exec.classpathScope>
        </properties>
    </action>
    <action>
        <actionName>CUSTOM-run via main 2</actionName>
        <displayName>run compact 2</displayName>
        <packagings>
            <packaging>*</packaging>
        </packagings>
        <goals>
            <goal>process-classes</goal>
            <goal>org.codehaus.mojo:exec-maven-plugin:3.5.1:exec</goal>
        </goals>
        <properties>
            <exec.vmArgs></exec.vmArgs>
            <exec.args>${exec.vmArgs} -classpath %classpath ${exec.mainClass} 
${exec.appArgs}</exec.args>
            <exec.mainClass>Compact2</exec.mainClass>
            <exec.executable>java</exec.executable>
            <exec.classpathScope>${classPathScope}</exec.classpathScope>
        </properties>
    </action>
</actions>


-mbien



>
> Thank you in advance for any suggestions,
>
> Ken
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists



Reply via email to