# Maven Webstart Plugin



## Siassei (16. Feb 2010)

Hallo,

nach mehreren Stunden suchen und probieren möchte ich maven .......... 

Ich würde gerne ein Maven-Projekt aufsetzen, dass mir automatisch ein Webstart-Anwendung erstellt, ohne die blöden key-tools Befehle manuell eingeben zu müssen und trotzdem ein Sign-Jar erhält. Sprich alle Informationen sollen in der pom stehen. Das muss doch gehen.

Über eine Lösung würde ich mich sehr sehr freuen

Gruß,
  Thomas


----------



## kama (16. Feb 2010)

Hallo,

hier gibt es ein Maven Plugin für den Web-Start....Maven Webstart Plug-In - Introduction

Ist der Rest denn schon in Ordnung und läßt sich übersetzen etc. ? 

MfG
Karl Heinz Marbaise


----------



## Siassei (16. Feb 2010)

Ich komm nicht mehr weiter :-(

Damit sich Fragen zur Projektstruktur erledigen habe ich das Projekt mal angehängt. Beim Build erhalte ich folgende Fehler in der Console
Build mit der Option -e

```
NetBeans: Executing '/home/siassei/Tools/maven2/bin/mvn -Dnetbeans.execution=true clean install -e'
NetBeans:      JAVA_HOME=/usr/lib/jvm/java
+ Error stacktraces are turned on.
Scanning for projects...
------------------------------------------------------------------------
Building Test2
   task-segment: [clean, install]
------------------------------------------------------------------------
[clean:clean]
Deleting directory /home/siassei/.NetBeansProjects/Test2/target
[resources:resources]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
skip non existing resourceDirectory /home/siassei/.NetBeansProjects/Test2/src/main/resources
[compiler:compile]
Compiling 2 source files to /home/siassei/.NetBeansProjects/Test2/target/classes
[compiler:compile]
Nothing to compile - all classes are up to date
[resources:testResources]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
skip non existing resourceDirectory /home/siassei/.NetBeansProjects/Test2/src/test/resources
[compiler:testCompile]
Compiling 1 source file to /home/siassei/.NetBeansProjects/Test2/target/test-classes
[surefire:test]
Surefire report directory: /home/siassei/.NetBeansProjects/Test2/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running edu.regensburg.tm.temp.test.test2.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.031 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[jar:jar]
Building jar: /home/siassei/.NetBeansProjects/Test2/target/Test2-1.0.jar
[install:install]
Installing /home/siassei/.NetBeansProjects/Test2/target/Test2-1.0.jar to /home/siassei/.m2/repository/edu/regensburg/tm/temp/test/Test2/1.0/Test2-1.0.jar
Preparing webstart:jnlp
------------------------------------------------------------------------
Building Test2
------------------------------------------------------------------------
[WARNING] Removing: jnlp from forked lifecycle, to prevent recursive invocation.
[resources:resources]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
skip non existing resourceDirectory /home/siassei/.NetBeansProjects/Test2/src/main/resources
[compiler:compile]
Nothing to compile - all classes are up to date
[compiler:compile]
Nothing to compile - all classes are up to date
[resources:testResources]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
skip non existing resourceDirectory /home/siassei/.NetBeansProjects/Test2/src/test/resources
[compiler:testCompile]
Nothing to compile - all classes are up to date
[surefire:test]
Surefire report directory: /home/siassei/.NetBeansProjects/Test2/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running edu.regensburg.tm.temp.test.test2.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.028 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[jar:jar]
[webstart:jnlp]
------------------------------------------------------------------------
[ERROR]BUILD ERROR
------------------------------------------------------------------------
Failure to run the plugin: 

------------------------------------------------------------------------
Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Failure to run the plugin: 
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:719)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
        at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:616)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.MojoExecutionException: Failure to run the plugin: 
        at org.codehaus.mojo.webstart.AbstractJnlpMojo.execute(AbstractJnlpMojo.java:289)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
        ... 17 more
Caused by: java.lang.NullPointerException
        at org.codehaus.mojo.webstart.AbstractJnlpMojo.execute(AbstractJnlpMojo.java:214)
        ... 19 more
------------------------------------------------------------------------
Total time: 7 seconds
Finished at: Tue Feb 16 19:00:21 CET 2010
Final Memory: 18M/35M
------------------------------------------------------------------------
```


----------



## Siassei (16. Feb 2010)

pom.xml

```
<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>edu.regensburg.tm.temp.test</groupId>
    <artifactId>Test2</artifactId>

    <packaging>jar</packaging>

    <version>1.0</version>
    <name>Test2</name>


    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.6</source>
                        <target>1.6</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>

        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo.webstart</groupId>
                <artifactId>webstart-maven-plugin</artifactId>

                <executions>
                    <execution>
                        <phase>install</phase>
                        <goals>
                            <goal>jnlp</goal>
                        </goals>
                    </execution>
                </executions>

                <configuration>
                    <outputDirectoryName>webstart</outputDirectoryName>
                    <excludeTransitive>false</excludeTransitive>

                    <jnlpFiles>
                        <jnlpFile>
                            <templateFilename>template.vm</templateFilename>
                            <outputFilename>Test2.jnlp</outputFilename>
                            <jarResources>
                                <jarResource>
                                    <groupId>edu.regensburg.tm.temp.test</groupId>
                                    <artifactId>Test2</artifactId>
                                    <version>${project.version}</version>
                                    <mainClass>edu.regensburg.tm.temp.test.test2.App</mainClass>
                                </jarResource>
                            </jarResources>
                        </jnlpFile>
                    </jnlpFiles>

                    <sign>
                        <keystore>/tmp/myappkeystore</keystore>
                        <keypass>m2m2m2</keypass>
                        <storepass>m2m2m2</storepass>
                        <alias>foobar</alias>
                        <validity>3650</validity>

                        <dnameCn>Insane Programming</dnameCn>
                        <dnameOu>Software Development</dnameOu>
                        <dnameO>Insane Programming</dnameO>
                        <dnameL>Maldegem</dnameL>
                        <dnameSt>Oost-Vlaanderen</dnameSt>
                        <dnameC>BE</dnameC>
                        <verify>false</verify>
                        <keystoreConfig>
                            <delete>true</delete>
                            <gen>true</gen>
                        </keystoreConfig>
                    </sign>
                    <outputJarVersions>true</outputJarVersions>
                    <verbose>true</verbose>
                    <unsign>true</unsign>
                    <verifyjar>false</verifyjar>
                </configuration>
            </plugin>

        </plugins>
    </build>


    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.0.4</version>
        </dependency>
        <dependency>
            <groupId>commons-cli</groupId>
            <artifactId>commons-cli</artifactId>
            <version>1.0</version>
        </dependency>

    </dependencies>

</project>
```

template.vm

```
<?xml version="1.0" encoding="utf-8"?>
<jnlp
    spec="$jnlpspec"
    codebase="$project.Url"
    href="$outputFile">
  <information>
    <title>$project.Name</title>
    <vendor>$project.Organization.Name</vendor>
    <homepage href="$project.Url"/>
    <description>$project.Description</description>
#if($offlineAllowed)
    <offline-allowed/>
#end
  </information>
#if($allPermissions)
  <security>
     <all-permissions/>
  </security>
#end
  <resources>
    <j2se version="$j2seVersion"/>
     $dependencies
  </resources>
  <application-desc main-class="$mainClass"/>
</jnlp>
```


----------



## maki (16. Feb 2010)

Bekomme dieselbe NPE, kenne das webstart plugin aber nicht :bahnhof:


----------



## kama (17. Feb 2010)

Hallo,

also ich habe das Ding mal etwas genauer angeschaut...Die Meldung rührt daher, dass die mainClass nicht korrekt konfiguriert ist (Quelltext und Exception Ausgabe)....Das scheint die Ursache zu sein....Aber leider weiß ich auch nicht wie man es richtig macht...
MfG
Karl Heinz Marbaise


----------



## Siassei (17. Feb 2010)

Danke für den Tipp mit der MainClass. Ich dachte immer, dass es an der Konfiguration liegt.

Mit dem Eintrag

```
<mainClass>org.apache.commons.cli.BasicParser</mainClass>
```
funktioniert es. Komisch, da wiedersprechen sich die Beispiele auf der Homepage des Projektes. Mals so, dann so


----------



## Siassei (17. Feb 2010)

Ok. Das war es nicht. Hmm, ich habe nun die Orginal-POM kopiert und mainClass wieder auf meine Klasse gesetzt. Jetzt kompiliert alles schön durch und der sign-Check wird erfolgreich durchgeführt.

```
<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>edu.regensburg.tm.temp.test.test2</groupId>
    <artifactId>Test2</artifactId>

    <packaging>jar</packaging>

    <version>1.0</version>
    <name>Test2</name>


    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.5</source>
                        <target>1.5</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>

        <plugins>
            
            <plugin>
                <groupId>org.codehaus.mojo.webstart</groupId>
                <artifactId>webstart-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>install</phase> 

                        <goals>
                            <goal>jnlp</goal> <!-- use jnlp, jnlp-inline or jnlp-single as appropriate -->
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <!--outputDirectory></outputDirectory--> <!-- not required?? -->

           <!--
           Set to true to exclude all transitive dependencies. Default is false.
           -->
                    <excludeTransitive>false</excludeTransitive>

                    <!-- The path where the libraries are stored within the jnlp structure. not required. by default the libraries are within the working directory -->
                   <!-- <libPath>lib</libPath> //-->

                    <!-- [optional] transitive dependencies filter - if omitted, all transitive dependencies are included -->
                    <dependencies>
                        <!-- Note that only groupId and artifactId must be specified here. because of a limitation of the Include/ExcludesArtifactFilter -->
                        <includes>
                            <include>commons-logging:commons-logging</include>
                            <include>commons-cli:commons-cli</include>
                        </includes>
                        <!-- excludes>
                <exclude></exclude>
             <excludes-->
                    </dependencies>

                    <!--resourcesDirectory>${project.basedir}/src/main/jnlp/resources</resourcesDirectory--> <!-- default value -->

           <!-- JNLP generation -->
                    <jnlp>
                        <!-- default values -->
             <!--inputTemplateResourcePath>${project.basedir}</inputTemplateResourcePath-->
             <!--inputTemplate>src/main/jnlp/template.vm</inputTemplate--> <!-- relative to inputTemplateResourcePath -->
                        <outputFile>Test2.jnlp</outputFile> <!-- defaults to launch.jnlp -->

             <!-- used to automatically identify the jar containing the main class. -->
             <!-- this is perhaps going to change -->
<!--                        <mainClass>org.apache.commons.cli.BasicParser</mainClass> //-->
                        <mainClass>edu.regensburg.tm.temp.test.test2.App</mainClass>
                    </jnlp>

                    <!-- SIGNING -->
           <!-- defining this will automatically sign the jar and its dependencies, if necessary -->
                    <sign>
                        <keystore>/tmp/myappkeystore</keystore>
                        <keypass>m2m2m2</keypass>  <!-- we need to override passwords easily from the command line. ${keypass} -->
                        <storepass>m2m2m2</storepass> <!-- ${storepass} -->
             <!--storetype>fillme</storetype-->
                        <alias>NB-JWS</alias>

                        <!--validity>fillme</validity-->
                        <validity>3650</validity>

                        <!-- only required for generating the keystore -->
             <!--dnameCn>fillme</dnameCn>
             <dnameOu>fillme</dnameOu>
             <dnameO>fillme</dnameO>
             <dnameL>fillme</dnameL>
             <dnameSt>fillme</dnameSt>
             <dnameC>fillme</dnameC-->
                        <dnameCn>Insane Programming</dnameCn>
                        <dnameOu>Software Development</dnameOu>
                        <dnameO>Insane Programming</dnameO>
                        <dnameL>Maldegem</dnameL>
                        <dnameSt>Oost-Vlaanderen</dnameSt>
                        <dnameC>BE</dnameC>

                        <verify>true</verify> <!-- verify that the signing operation succeeded -->

             <!-- KEYSTORE MANAGEMENT -->
                        <keystoreConfig>
                            <delete>true</delete> <!-- delete the keystore -->
                            <gen>true</gen>       <!-- optional shortcut to generate the store. -->
                        </keystoreConfig>
                    </sign>

                    <!-- BUILDING PROCESS -->

                    <pack200>true</pack200>
                    <gzip>true</gzip> <!-- default force when pack200 false, true when pack200 selected ?? -->

           <!-- causes a version attribute to be output in each jar resource element, optional, default is false -->
                    <outputJarVersions>true</outputJarVersions>

                    <!--install>false</install--> <!-- not yet supported -->
                    <verbose>true</verbose>

                </configuration>
            </plugin>
        </plugins>
    </build>


    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>commons-cli</groupId>
            <artifactId>commons-cli</artifactId>
            <version>1.2</version>
        </dependency>

    </dependencies>

</project>
```

Nun gibt es ein anderes Problem. Ich bekomme beim ausführen aus einer Website eine NullPointerExc.
Linux-Console:

```
javaws http://enzinger-th.de/webstart/test/Test2.jnlp
net.sourceforge.jnlp.LaunchException: Fatal: Launch Error: Could not launch JNLP file.
        at net.sourceforge.jnlp.Launcher.launchApplication(Launcher.java:447)
        at net.sourceforge.jnlp.Launcher$TgThread.run(Launcher.java:714)
Caused by: java.lang.NullPointerException
        at net.sourceforge.jnlp.Launcher.launchApplication(Launcher.java:427)
        ... 1 more
Caused by: 
java.lang.NullPointerException
        at net.sourceforge.jnlp.Launcher.launchApplication(Launcher.java:427)
        at net.sourceforge.jnlp.Launcher$TgThread.run(Launcher.java:714)
```
Test2.jnlp

```
<?xml version="1.0" encoding="utf-8"?>
<jnlp
    spec="1.0+"
    codebase="$$codebase"
    href="Test2.jnlp">
  <information>
    <title>Test2</title>
    <vendor>Thomas Enzinger</vendor>
    <homepage href="http://www.enzinger-th.de"/>
    <description>Test - Project</description>
    <offline-allowed/>
  </information>
  <security>
     <all-permissions/>
  </security>
  <resources>
    <j2se version="1.5+"/>
     
<jar href="Test2-1.0.jar" version="1.0" main="true"/>
<jar href="commons-logging-1.1.1.jar" version="1.1.1"/>
<jar href="commons-cli-1.2.jar" version="1.2"/>

  </resources>
  <application-desc main-class="edu.regensburg.tm.temp.test.test2.App"/>
</jnlp>
```

Verwende ich die Source in einem Netbeans-Projekt und kompiliere es als Webstart funktioniert es

```
javaws http://enzinger-th.de/webstart/test/launch.jnlp
```


----------

