RunDebugJarProjects

What Netbeans Ant projects do
  • The manifest for the jar contains the Main-Class attribute
  • It also contains the Class-Path attribute that lists all the dependencies of the jar and puts then in the attribute value (assuming all dependency jars to be in lib/ subdirectory)
  • the project's jar is created in the dist/ directory and all it's dependencies are copied to the dist/lib/ subdirectory, so that the actual location matches the location described in the manifest
  • then the application is started by the Ant's java task which does the equivalent of "java -jar <project's jar>"
  • The IO of the process is handled by Ant and printed right into the ant build's Output tab.
How to proceed in Maven?
  • Run package phase
  • Run assembly:directory -Ddescriptor=<path-to-our-descriptor. That one will create the same layout as the netbeans ant build script does. The question is where to place the assembly descriptor file.
    1. One option is to copy it into the project directory. Then we should probably add the assembly:directory goal to the pom.xml file and make it part of the default build.
    2. Or we can somehow bundle the assembly part with the netbeans-run-plugin and run it from there. That way everything is clearly encapsulated and doens't interfere with the user's pom.xml setup.
      assembly.xml
      <assembly>
       <id>netbeans</id>
      <includeBaseDirectory>false</includeBaseDirectory>
      <fileSets>
         <fileSet>
            <directory>target</directory>
            <outputDirectory></outputDirectory>
            <includes>
              <include>*.jar</include>
            </includes>
         </fileSet>
      </fileSets>
       <dependencySets>
         <dependencySet>
           <outputDirectory>lib</outputDirectory>
           <unpack>false</unpack>
           <scope>runtime</scope>
         </dependencySet>
       </dependencySets>
      </assembly>
  • Have a special netbeans-run-plugin. That one will call
    java -jar <my artifact>.jar
    It also make sure the app is run by the NB Execution Engine and the in/out streams are linked together correctly.

That one will work correctly only if we run the assembly:directory before it's run and once the users have this snippet in the pom.xml configuration:

Snippet of necessary maven-jar-plugin configuration
<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>foo.app.FooApp</mainClass>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib</classpathPrefix>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
  • For debugging we will need to pass the extra debugging VM switches to the application. For example,
    -J-Xdebug -J-Xnoagent -J-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8765
Customizer UI

The UI design for projects with jar packaging should resemble the UI of the default Netbeans J2SE project type.

What happens when setting a value in one of the fields:

Main Class

  1. into pom.xml insert the following snippet (or part of it, if there is already existing configuration)
    <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <configuration>
                        <archive>
                            <manifest>
                                <mainClass>foo.app.FooApp</mainClass>
                                <addClasspath>true</addClasspath>
                                <classpathPrefix>lib</classpathPrefix>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
            </plugins>

Arguments
These belong to he nbactions.xml configuration file, we will need to add them to run, debug, run-single and debug-single action mappings.

Working Directory

VM Options

Labels

 
(None)