Search code examples
javamavennetbeansnetbeans-platform

Display Maven Project version on Netbeans Application window


I have a Maven based Netbeans Application. By default the application window title is on this format:

<Application Name>{0}

Where {0} is replaced at runtime with the IDE build date it appears. Is there a way for this to automatically be the project's Maven version instead?

Right now I need to manually change this on each release. It's just prone to errors.

Update Added the following to the POM but it seem snot to have any effect and Netbeans shows red icons because is not finding some files for a Helps set I have in the module.

        <resources>
            <resource>
                <directory>${basedir}/src/main/nbm-branding/core/core.jar/org/netbeans/core/startup</directory>
                <filtering>true</filtering>
            </resource>
        </resources>

Solution

  • There are two ways to set the version number shown in the Help... About dialog.

    The easy way is to set the system property netbeans.buildnumber to some value in your application.
    The harder way is to put this key/value currentVersion=My Product 1.2.3 into the file named "branding/modules/org-netbeans-core.jar/org/netbeans/core/ui/Bundle.properties" below your suite, then rebuild and run.
    In NB 6.5 and later is the file location different: "branding/core/core.jar/org/netbeans/core/startup/Bundle.properties" 
    

    How do I set the version number automatically in maven-based applications?

    Within your branding-module use Maven placeholders in Bundle.properties and within the pom.xml filter the bundle by the maven-resources-plugin.

    Note: Some of the files below are ignored by default in version control by Netbeans so you might need to add them to preserve the changes.

    src/main/nbm-branding/core/core.jar/org/netbeans/core/startup/Bundle.properties:

    currentVersion=My app ${project.version}
    LBL_splash_window_title=Starting My app ${project.version}
    

    src/main/nbm-branding/modules/org-netbeans-core-windows.jar/org/netbeans/core/windows/view/ui/Bundle.properties:

    CTL_MainWindow_Title=My app ${project.version}
    CTL_MainWindow_Title_No_Project=My app ${project.version}
    

    src/main/nbm-branding/modules/org-netbeans-core.jar/org/netbeans/core/ui/Bundle.properties:

    LBL_ProductInformation=My app ${project.version}
    

    pom.xml:

    <build>
        <resources>
            <resource>
                <directory>${basedir}/src/main/nbm-branding</directory>
                <!-- f.e. allow replacing ${project.version} in all property files below src/main/nbm-branding -->
                <includes>
                    <include>**/*.properties</include>
                </includes>
                <filtering>true</filtering>
                <targetPath>${basedir}/target/filtered-nbm-branding</targetPath>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>nbm-maven-plugin</artifactId>
                <configuration>
                    <!-- use previously filtered branding sources -->
                    <brandingSources>${basedir}/target/filtered-nbm-branding</brandingSources>
                </configuration>
            </plugin>
            <!-- ... -->
        </plugins>
    </build>
    

    As answered by Netbeans Dream Team member.