dtuinstr opened a new issue, #9405:
URL: https://github.com/apache/netbeans/issues/9405

   ### Apache NetBeans version
   
   Apache NetBeans 30
   
   ### What happened
   
   Maven-based Java application projects run correctly in the IDE, but print a 
"no main manifest attribute" error (and do nothing else) when run from the 
command line. This occurs even if the project's "Run" property is set to the 
class containing `main()` and the project rebuilt. 
   
   A workaround found on the web (see "Anything Else" section) fixes the 
problem. The fix is to write additional entries to the "pom.xml" file.
   
   It appears setting the "Run" property should write these entries to the 
"pom.xml" file, but NetBeans does not do this.
   
   ### Language / Project Type / NetBeans Component
   
   _No response_
   
   ### How to reproduce
   
   In NetBeans: choose `New Project > Java with Maven > Java Application`, and 
fill in fields:
   
       Project Name    : Hello [fill this in]
       Project Location: /home/${userID}/NetBeansProjects [default]
       Project Folder  : ${ProjectLocation}/Hello [generated from Project Name]
       Group Id        : Example [fill this in]
       Version         : 1.0-SNAPSHOT [default]
       Package         : example.hello [generated from Group Id and Project 
Name]
   Click "OK"
   > Result: A new project is created with a default "Hello World" program 
already coded.
   
   In NetBeans: choose `Run > Clean and Build Project`
   > Result: The project builds successfully
   
   In a terminal window: `cd` to the project directory and the "target" 
subdirectory.
   > Result: you are in a directory containing "Hello-1.0-SNAPSHOT.jar".
   
   Give the command `java -jar Hello-1.0-SHAPSHOT.jar`.
   > Expected result: prints "Hello World!"
   > Actual result  : prints "no main manifest attribute, in 
Hello-1.0-SNAPSHOT.jar" (and nothing else)
   
   Some searching found this page in the NetBeans documentation: ["Packaging 
and Distributing Java Desktop 
Applications"](https://netbeans.apache.org/tutorial/main/kb/docs/java/javase-deploy/).
 It is outdated (building a project does not create "dist" and "build" folders 
as claimed), however the section "Setting the Main Class" seems applicable. So 
...
   
   In NetBeans: Right-click on the "Hello" project > choose "Properties" > 
click "Run", and fill in fields:
   
       Configuration    : <default config>  [already filled in with this]
       Main Class       : use "Browse" button, choose "example.hello.Hello"
       Arguments        : [blank, default]
       Working Directory: [blank, default]
       VM Options       : [blank, default]
   
   Click "OK"
   > Result:
   > "pom.xml" contents unchanged
   > new file "nbactions.xml" added (contents below)
   
   In NetBeans, do a "Clean and Build" of project, then on the command line run 
the resulting jar.
   > Result: same as before ("no main manifest attribute ..." message and 
nothing else).
   
   ### Did this work correctly in an earlier version?
   
   No / Don't know
   
   ### Operating System
   
   Linux Mint 22.1 Xia base: Ubuntu 24.04 noble
   
   ### JDK
   
   openjdk version "21.0.10" 2026-01-20 / OpenJDK Runtime Environment (build 
21.0.10+7-Ubuntu-124.04) / OpenJDK 64-Bit Server VM (build 
21.0.10+7-Ubuntu-124.04, mixed mode, sharing)
   
   ### Apache NetBeans packaging
   
   Apache NetBeans binary zip
   
   ### Anything else
   
   <details><summary>Workaround</summary>
   This workaround is from the site 
"https://www.javathinking.com/blog/netbeans-maven-project-not-adding-main-class-to-manifest/";.
 Curiously, it matches the instructions from documentation page listed above. 
However, it goes an extra step and shows what should have been added to the 
project section in the "pom.xml" file. Putting in the class path to the main 
class solves the problem. The program builds and runs as expected, printing 
"Hello World!".
   
       <build>  
           <plugins>  
               <plugin>  
                   <groupId>org.apache.maven.plugins</groupId>  
                   <artifactId>maven-jar-plugin</artifactId>  
                   <version>3.2.0</version> <!-- Version may vary -->  
                   <configuration>  
                       <archive>  
                           <manifest>  
                               <mainClass>example.hello.Hello</mainClass>  
                           </manifest>  
                       </archive>  
                   </configuration>  
               </plugin>  
           </plugins>  
       </build> 
   </details>
   
   <details><summary>Desired changes</summary>
   If a "Java with Maven | Java Application" project has a single `main()` 
method in it, NetBeans should build a "pom.xml" file that will create a 
runnable JAR file when the project is built. This is the most reasonable 
expectation from a user.
   
   If such a project has no `main()` method, or multiple `main()` methods, 
NetBeans should alert the user to this and suggest possible actions when the 
project is built.
   
   Otherwise, NetBeans' behavior or documentation should change so that a user 
can build a runnable JAR file with minimumal fuss or documentation searching. 
   - Preferably this would be a clearly surfaced option during project 
creation. 
   - Next best would be a dialog shown at the time of first build in which a 
user could set options for remaining builds. 
   - At the very least, when a user updates the "Main Class" field of the 
project's "Run" property, a section similar to that in the workaround above 
should appear in the project's "pom.xml" file. I suspect this is the currently 
designed behavior of NetBeans, and it is a bug that this does not happen.
   </details>
   
   <details><summary>From the NetBeans "About" window</summary>
   
       Product Version: Apache NetBeans IDE 30
       Java: 21.0.10; OpenJDK 64-Bit Server VM 21.0.10+7-Ubuntu-124.04
       Runtime: OpenJDK Runtime Environment 21.0.10+7-Ubuntu-124.04
       System: Linux version 6.8.0-117-generic running on amd64; UTF-8; en_US 
(nb)
       User directory: /home/dwight/.netbeans/30
       Cache directory: /home/dwight/.cache/netbeans/30
   </details>
   
   <details><summary>Project's "pom.xml" file contents</summary>
   
       <?xml version="1.0" encoding="UTF-8"?>
       <project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
           <modelVersion>4.0.0</modelVersion>
           <groupId>Example</groupId>
           <artifactId>Hello</artifactId>
           <version>1.0-SNAPSHOT</version>
           <packaging>jar</packaging>
           <properties>
               
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
               <maven.compiler.release>21</maven.compiler.release>
               <exec.mainClass>example.hello.Hello</exec.mainClass>
           </properties>
       </project>
   </details>
   
   <details><summary>Project's "pom.xml" file contents with workaround</summary>
   Note: the maven-jar-plugin version is from the workaround on the web. 
NetBeans should fill it in with an appropriate value.
   
       <?xml version="1.0" encoding="UTF-8"?>
       <project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
           <modelVersion>4.0.0</modelVersion>
           <groupId>Example</groupId>
           <artifactId>Hello</artifactId>
           <version>1.0-SNAPSHOT</version>
           <packaging>jar</packaging>
           <properties>
               
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
               <maven.compiler.release>21</maven.compiler.release>
               <exec.mainClass>example.hello.Hello</exec.mainClass>
           </properties>
           <build>  
               <plugins>  
                   <plugin>  
                       <groupId>org.apache.maven.plugins</groupId>  
                       <artifactId>maven-jar-plugin</artifactId>  
                       <version>3.2.0</version>
                       <configuration>  
                           <archive>  
                               <manifest>  
                                   <mainClass>example.hello.Hello</mainClass>  
                               </manifest>  
                           </archive>  
                       </configuration>  
                   </plugin>  
               </plugins>  
           </build>  
       </project>
   </details>
   
   <details><summary>Project's "nbactions.xml" file contents</summary>
   
       <?xml version="1.0" encoding="UTF-8"?>
       <actions>
               <action>
                   <actionName>run</actionName>
                   <packagings>
                       <packaging>jar</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.appArgs></exec.appArgs>
                       <exec.mainClass>example.hello.Hello</exec.mainClass>
                       <exec.executable>java</exec.executable>
                   </properties>
               </action>
               <action>
                   <actionName>debug</actionName>
                   <packagings>
                       <packaging>jar</packaging>
                   </packagings>
                   <goals>
                       <goal>process-classes</goal>
                       
<goal>org.codehaus.mojo:exec-maven-plugin:3.5.1:exec</goal>
                   </goals>
                   <properties>
                       
<exec.vmArgs>-agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address}</exec.vmArgs>
                       <exec.args>${exec.vmArgs} -classpath %classpath 
${exec.mainClass} ${exec.appArgs}</exec.args>
                       <exec.appArgs></exec.appArgs>
                       <exec.mainClass>example.hello.Hello</exec.mainClass>
                       <exec.executable>java</exec.executable>
                       <jpda.listen>true</jpda.listen>
                   </properties>
               </action>
               <action>
                   <actionName>profile</actionName>
                   <packagings>
                       <packaging>jar</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>example.hello.Hello</exec.mainClass>
                       <exec.executable>java</exec.executable>
                       <exec.appArgs></exec.appArgs>
                   </properties>
               </action>
           </actions>
   </details>
   
   <details><summary>$ java -version</summary>
   
       openjdk version "21.0.10" 2026-01-20
       OpenJDK Runtime Environment (build 21.0.10+7-Ubuntu-124.04)
       OpenJDK 64-Bit Server VM (build 21.0.10+7-Ubuntu-124.04, mixed mode, 
sharing)
   </details>
   
   <details><summary>$ mvn --version</summary>
   
       Apache Maven 3.8.7
       Maven home: /usr/share/maven
       Java version: 21.0.10, vendor: Ubuntu, runtime: 
/usr/lib/jvm/java-21-openjdk-amd64
       Default locale: en_US, platform encoding: UTF-8
       OS name: "linux", version: "6.8.0-117-generic", arch: "amd64", family: 
"unix"
   </details>
   
   <details><summary>$ ~/opt/netbeans/bin/netbeans --list</summary>
   
       Detected 2x HiDPI scaling in Xft.dpi setting; setting GDK_SCALE=2
       WARNING: package com.sun.java.swing.plaf.windows not in java.desktop
       WARNING: package com.apple.laf not in java.desktop
       Need to use also --modules, --refresh
   </details>
   
   <details><summary>$ ~/opt/netbeans/platform/lib/nbexec --list --modules 
--refresh</summary>
   
       May 24, 2026 11:40:14 AM org.netbeans.ProxyURLStreamHandlerFactory 
register
       SEVERE: No way to find original stream handler for jar protocol
       java.lang.reflect.InaccessibleObjectException: Unable to make field 
transient java.net.URLStreamHandler java.net.URL.handler accessible: module 
java.base does not "opens java.net" to unnamed module @13221655
            at 
java.base/java.lang.reflect.AccessibleObject.throwInaccessibleObjectException(AccessibleObject.java:391)
            at 
java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:367)
            at 
java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:315)
            at 
java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:183)
            at java.base/java.lang.reflect.Field.setAccessible(Field.java:177)
            at 
org.netbeans.ProxyURLStreamHandlerFactory.register(ProxyURLStreamHandlerFactory.java:59)
            at org.netbeans.JarClassLoader.<clinit>(JarClassLoader.java:131)
            at org.netbeans.MainImpl.execute(MainImpl.java:166)
            at org.netbeans.MainImpl.main(MainImpl.java:60)
            at org.netbeans.Main.main(Main.java:58)
   
       java.io.FileNotFoundException: /var/cache/lastModified/all-checksum.txt 
(No such file or directory)
            at java.base/java.io.FileOutputStream.open0(Native Method)
            at 
java.base/java.io.FileOutputStream.open(FileOutputStream.java:289)
            at 
java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:230)
            at 
java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:179)
            at org.netbeans.Stamps.compareAndUpdateFile(Stamps.java:449)
            at org.netbeans.Stamps.stamp(Stamps.java:342)
            at org.netbeans.Stamps.moduleJARs(Stamps.java:285)
            at org.netbeans.Stamps.file(Stamps.java:175)
            at org.netbeans.Stamps.asByteBuffer(Stamps.java:180)
            at org.netbeans.Stamps.asByteBuffer(Stamps.java:160)
            at org.netbeans.Archive.<init>(Archive.java:95)
            at 
org.netbeans.JarClassLoader.initializeCache(JarClassLoader.java:98)
            at org.netbeans.MainImpl$BootClassLoader.run(MainImpl.java:331)
            at org.netbeans.CLIHandler.initialize(CLIHandler.java:573)
            at org.netbeans.CLIHandler.initialize(CLIHandler.java:359)
            at org.netbeans.MainImpl.execute(MainImpl.java:181)
            at org.netbeans.MainImpl.main(MainImpl.java:60)
            at org.netbeans.Main.main(Main.java:58)
       Code Name                                   Version  State    
       ------------------------------------------- -------- ---------
       org.netbeans.modules.core.kit               1.63     Enabled  
       org.netbeans.libs.junit4                    1.50     Installed
       org.netbeans.libs.junit5                    1.29     Installed
       org.netbeans.swing.plaf                     1.74     Enabled  
       org.netbeans.modules.autoupdate.services    1.88     Enabled  
       org.netbeans.html.presenters.spi            1.8.2    Installed
       org.netbeans.modules.options.api            1.77     Enabled  
       org.netbeans.core.network                   1.44     Enabled  
       org.netbeans.api.search                     1.53     Installed
       org.openide.modules                         7.80     Enabled  
       org.openide.filesystems.nb                  9.42     Enabled  
       org.netbeans.modules.keyring                1.56     Enabled  
       org.netbeans.core.windows                   2.117    Enabled  
       org.netbeans.api.templates                  1.40     Enabled  
       org.openide.util.lookup                     8.66     Enabled  
       org.netbeans.swing.laf.flatlaf              1.25     Enabled  
       org.netbeans.modules.masterfs.nio2          1.47     Enabled  
       org.netbeans.modules.autoupdate.cli         1.46     Enabled  
       org.netbeans.modules.uihandler              2.67     Installed
       org.netbeans.api.annotations.common         1.60     Enabled  
       org.netbeans.modules.janitor                1.25     Enabled  
       org.netbeans.modules.templatesui            1.35     Installed
       org.netbeans.core.output2                   1.74     Enabled  
       org.netbeans.core.netigso                   1.63     Enabled  
       org.netbeans.libs.jna.platform              2.27     Enabled  
       org.netbeans.bootstrap                      2.111    Enabled  
       org.openide.execution                       9.35     Installed
       org.netbeans.modules.htmlui                 1.17     Installed
       org.netbeans.modules.print                  7.58     Enabled  
       org.netbeans.spi.quicksearch                1.59     Enabled  
       org.openide.util                            9.40     Enabled  
       org.netbeans.modules.spi.actions            1.60     Installed
       org.openide.windows                         6.109    Enabled  
       org.apache.commons.logging                  1.3.5    Installed
       org.netbeans.modules.autoupdate.ui          1.78     Enabled  
       org.apache.commons.codec                    1.21.0   Installed
       org.netbeans.modules.sampler                1.46     Enabled  
       org.netbeans.core.io.ui                     1.62     Enabled  
       org.netbeans.html.xhr4j                     1.8.2    Installed
       org.netbeans.api.progress.compat8           1.79     Installed
       org.openide.dialogs                         7.79     Enabled  
       org.netbeans.modules.templates              1.39     Enabled  
       org.openide.awt                             7.100    Enabled  
       org.openide.actions                         6.71     Enabled  
       org.openide.compat                          6.72     Installed
       org.netbeans.api.io                         1.35     Enabled  
       org.netbeans.api.intent                     1.34     Enabled  
       org.openide.loaders                         7.102    Enabled  
       org.openide.nodes                           7.77     Enabled  
       org.netbeans.modules.keyring.fallback       1.40     Enabled  
       org.netbeans.swing.outline                  1.66     Enabled  
       org.netbeans.api.progress.nb                1.80     Enabled  
       org.openide.io                              1.81     Enabled  
       net.java.html.sound                         1.8.2    Installed
       org.netbeans.api.progress                   1.80     Enabled  
       org.openide.util.ui                         9.41     Enabled  
       net.java.html.geo                           1.8.2    Installed
       org.openide.util.ui.svg                     1.26     Enabled  
       org.netbeans.libs.testng                    1.46     Installed
       org.netbeans.libs.javafx                    2.39     Installed
       org.openide.text                            6.101    Enabled  
       org.netbeans.libs.asm                       5.35     Enabled  
       org.netbeans.libs.osgi                      1.54     Enabled  
       org.netbeans.libs.flatlaf                   1.26     Enabled  
       org.netbeans.modules.masterfs.linux         1.45     Enabled  
       org.netbeans.modules.favorites              1.78     Enabled  
       org.netbeans.modules.options.keymap         1.69     Enabled  
       net.java.html.json                          1.8.2    Installed
       org.netbeans.core.startup                   1.95.0.1 Enabled  
       org.apache.commons.commons_io               2.23     Installed
       org.netbeans.modules.queries                1.75     Enabled  
       org.netbeans.core.execution                 1.74     Installed
       org.netbeans.libs.javax.inject              2.67     Installed
       org.netbeans.modules.editor.mimelookup      1.72     Enabled  
       org.netbeans.core                           3.83     Enabled  
       org.netbeans.swing.laf.dark                 2.27.0.2 Enabled  
       org.netbeans.modules.sendopts               2.68     Enabled  
       net.java.html.boot                          1.8.2    Installed
       net.java.html.boot.script                   1.8.2    Installed
       org.netbeans.libs.felix                     2.47     Enabled  
       org.netbeans.modules.progress.ui            1.65     Enabled  
       org.netbeans.core.nativeaccess              1.63     Enabled  
       org.netbeans.modules.junitlib               1.37     Installed
       org.netbeans.modules.masterfs.ui            2.35.0.2 Enabled  
       org.netbeans.core.multiview                 1.76     Installed
       org.netbeans.modules.settings               1.81     Enabled  
       net.java.html.boot.fx                       1.8.2    Installed
       org.netbeans.api.visual                     2.80     Installed
       org.netbeans.modules.masterfs               2.87.0.2 Enabled  
       org.netbeans.lib.uihandler                  1.77     Installed
       org.netbeans.modules.keyring.impl           1.56     Enabled  
       net.java.html                               1.8.2    Installed
       org.openide.explorer                        6.94     Enabled  
       org.openide.filesystems.compat8             9.41     Enabled  
       org.netbeans.libs.jsvg                      2.4      Enabled  
       org.netbeans.core.multitabs                 1.44.0.1 Enabled  
       org.netbeans.modules.editor.mimelookup.impl 1.64     Enabled  
       org.openide.filesystems                     9.45     Enabled  
       org.netbeans.core.osgi                      1.54     Installed
       org.netbeans.api.scripting                  1.29     Enabled  
       org.netbeans.api.htmlui                     1.40     Installed
       org.netbeans.modules.netbinox               1.73     Installed
       org.netbeans.swing.tabcontrol               1.89     Enabled  
       org.netbeans.api.dashboard                  0.9      Installed
       org.netbeans.libs.jna                       2.27     Enabled  
       org.netbeans.html.ko4j                      1.8.2    Installed
       org.netbeans.core.ui                        1.77     Enabled  
       org.apache.commons.lang3                    3.17.0   Installed
       org.netbeans.core.startup.base              1.94.0.1 Enabled  
       org.netbeans.modules.javahelp               2.73     Installed
       org.openide.execution.compat8               9.34     Installed
       org.netbeans.libs.jsr223                    1.67     Installed
       ------------------------------------------- -------- ---------
   </details>
   
   ### Are you willing to submit a pull request?
   
   No


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
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