apache / netbeans

Apache NetBeans
https://netbeans.apache.org/
Apache License 2.0
2.63k stars 843 forks source link

VM options in maven project properties used by "run project" action but not by "run file via main()" action #7711

Open insastrasbge1 opened 3 weeks ago

insastrasbge1 commented 3 weeks ago

Apache NetBeans version

Apache NetBeans 22

What happened

When you define a VM option in the properties of a maven project, this option is copied into the exec.vmArgs parameter of the “run project” action, but not into the same parameter of the “run file via main()” action.

Language / Project Type / NetBeans Component

Java Application Maven Project

How to reproduce

A particularly painful example: Under Windows, there is an incompatibility between the netbeans console and the output of a program defined by a “java with maven; java application” project: 1) Create a new “java with maven; java application” 2) in the main method automaticaly generated, change "Hello World!" by "déjà" 3) run the project (F6) ==> you get in the netbeans output console : d�j� 4) go to project properties ; run ; vm options and add -Dstdout.encoding=UTF-8 5) run again the project (F6) ==> you get in the netbeans output console : déjà 6) now run the file (shift-F6) ==> you get in the netbeans output console : d�j� there is a notable difference between running the project and running the current file (containing a class with a main method)

You can see the difference by opening “Actions” in the project properties and successively selecting the actions “run project” and “run file via main()”. Under "run projet" you have : exec.vmArgs=-Dstdout.encoding=UTF-8 Under "run file via main()" you have only : exec.vmArgs= (empty)

it's the same for “debug project” and “debug file by main()”.

Did this work correctly in an earlier version?

No / Don't know

Operating System

Windows 11

JDK

java version "22" 2024-03-19 Java(TM) SE Runtime Environment Oracle GraalVM 22+36.1 (build 22+36-jvmci-b02) Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 22+36.1 (build 22+36-jvmci-b02, mixed mode, sharing)

Apache NetBeans packaging

Apache NetBeans provided installer

Anything else

No response

Are you willing to submit a pull request?

No

insastrasbge1 commented 3 weeks ago

Workaround : you can fix the problem manually by going to project properties ; Actions ; “run file via main()” and add -Dstdout.encoding=UTF-8 (or any other vm options) to exec.vmArgs (the first line becomes exec.vmArgs=-Dstdout.encoding=UTF-8)

neilcsmith-net commented 3 weeks ago

Yes, the Run section is just a shortcut to setting up some of the actions. If you set the actions directly, you'll notice the Run section gets disabled.

You might want to set up environment variables on your system for this anyway - see comments on #4261 Welcome to the joys of encoding on Windows!

mbien commented 3 weeks ago

the project run config is specific to the main entry point of the project. This is used when the the project run button is pressed.

The run-single action simply tries to run the selected file, it won't use the project config args which were defined for the main entry point.

You can add more run actions with arbitrary configs via nbactions.xml looks like this:

    <action>
        <actionName>CUSTOM-custom custom codec</actionName>
        <displayName>custom codec</displayName>
        <goals>
            <goal>compile</goal>
            <goal>exec:java</goal>
        </goals>
        <properties>
            <exec.mainClass>dev.mbien.mavenproject3.Mavenproject3</exec.mainClass>
            <stdout.encoding>US-ASCII</stdout.encoding>
        </properties>
    </action>

this will appear under the "Run Maven" context menu.

I don't know if you can add properties to the run-single action, I never tried doing that so far.