Question

I created a simple Hello World Swing application that compiles and runs just fine in Eclipse. I'm now trying to transfer this application over to a Maven package structure and run it as a Java Web-Start application, which is causing me great pain. After running "mvn clean install", javaws appears to load for several seconds and then quit.

Here are a few things for reference. My (very simple) project should be fully reproducible:

Package structure (from tree):

├── pom.xml
├── readme.txt
├── SwingWebstartMaven-Client
│   ├── pom.xml
│   ├── src
│   │   ├── main
│   │   │   ├── java
│   │   │   │   └── com
│   │   │   │       └── shaunabram
│   │   │   │           └── swingwebstartmaven
│   │   │   │               ├── HelloWorldSwing.class
│   │   │   │               └── HelloWorldSwing.java
│   │   │   ├── jnlp
│   │   │   │   └── template.vm
│   │   │   └── resources
│   │   └── test
│   └── target
│       ├── classes
│       │   └── com
│       │       └── shaunabram
│       │           └── swingwebstartmaven
│       │               └── HelloWorldSwing.class
│       ├── jnlp
│       │   ├── launch.jnlp
│       │   ├── lib
│       │   │   └── SwingWebstartMaven-Client-1.0.jar
│       │   └── SwingWebstartMavenExample-KeyStore
│       ├── maven-archiver
│       │   └── pom.properties
│       ├── surefire
│       ├── SwingWebstartMaven-Client-1.0.jar
│       └── SwingWebstartMaven-Client-1.0.zip
└── SwingWebstartMaven-Web
    ├── pom.xml
    ├── src
    │   ├── main
    │   │   ├── java
    │   │   ├── resources
    │   │   └── webapp
    │   │       ├── index.html
    │   │       └── WEB-INF
    │   │           └── web.xml
    │   └── test
    └── target
        ├── classes
        ├── maven-archiver
        │   └── pom.properties
        ├── surefire
        ├── SwingWebstartMaven-Web-1.0
        │   ├── index.html
        │   ├── META-INF
        │   └── WEB-INF
        │       ├── classes
        │       └── web.xml
        └── SwingWebstartMaven-Web-1.0.war

Primary 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>com.shaunabram.swingwebstartmaven</groupId>
    <artifactId>SwingWebstartMaven</artifactId>
    <packaging>pom</packaging>
    <version>1.0</version>
    <name>SwingWebstartMaven Project</name>

    <modules>
        <module>SwingWebstartMaven-Client</module>
        <module>SwingWebstartMaven-Web</module>
    </modules>

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

                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>tomcat-maven-plugin</artifactId>
                    <configuration>
                        <url>http://localhost:8080/manager</url>
                        <username>tomcat</username>
                        <password>tomcat</password>
                    </configuration>
                </plugin>

            </plugins>
        </pluginManagement>
    </build>

</project>

SwingWebstart-Client 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>
    <parent>
        <groupId>com.shaunabram.swingwebstartmaven</groupId>
        <artifactId>SwingWebstartMaven</artifactId>
        <version>1.0</version>
    </parent>
    <artifactId>SwingWebstartMaven-Client</artifactId>
    <packaging>jar</packaging>
    <name>SwingWebstartMaven Client</name>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo.webstart</groupId>
                <artifactId>webstart-maven-plugin</artifactId>
                <version>1.0-beta-2</version>

                <executions>
                    <execution>
                        <id>package</id>
                        <phase>package</phase>
                        <goals>
                            <goal>jnlp-inline</goal>
                        </goals>
                    </execution>
                </executions>

                <configuration>
                    <jnlp>
                        <outputFile>launch.jnlp</outputFile>
                        <mainClass>com.shaunabram.swingwebstartmaven.HelloWorldSwing</mainClass>
                    </jnlp>

                    <libPath>lib</libPath>

                    <sign>
                        <keystore>SwingWebstartMavenExample-KeyStore</keystore>
                        <keypass>YourPassword</keypass>
                        <storepass>YourPassword</storepass>
                        <alias>SwingWebstartMavenExample</alias>
                        <validity>3650</validity>

                        <dnameCn>Your Name</dnameCn>
                        <dnameOu>Organizational Unit</dnameOu>
                        <dnameO>Organization</dnameO>
                        <dnameL>City or Locality</dnameL>
                        <dnameSt>State or Province</dnameSt>
                        <dnameC>US</dnameC>

                        <verify>true</verify>
                        <keystoreConfig>
                            <delete>true</delete>
                            <gen>true</gen>
                        </keystoreConfig>
                    </sign>

                    <pack200>false</pack200>
                    <gzip>true</gzip>
                    <outputJarVersions>false</outputJarVersions>
                    <verbose>true</verbose>

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

</project>

SwingWebstartMaven-Web 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>
    <parent>
        <groupId>com.shaunabram.swingwebstartmaven</groupId>
        <artifactId>SwingWebstartMaven</artifactId>
        <version>1.0</version>
    </parent>

    <artifactId>SwingWebstartMaven-Web</artifactId>
    <packaging>war</packaging>
    <name>SwingWebstartMaven Web</name>

    <dependencies>

    </dependencies>

</project>

HelloWorldSwing.java:

package com.shaunabram.swingwebstartmaven;

import javax.swing.JFrame;
import javax.swing.JLabel;

public class HelloWorldSwing {
  public static void main(String[] args) {
    JFrame frame = new JFrame("HelloWorldSwing");
    final JLabel label = new JLabel("Hello World");
    frame.getContentPane().add(label);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
  }
}

template.vm:

<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+" codebase="http://localhost:8080/SwingWebstartMaven-Web/webstart" href="$outputFile">
 <information>
    <title>Swing Webstart Maven Project</title>
    <vendor>ShaunAbram</vendor>
 </information>
 <security>
 <all-permissions/>
 </security>
 <resources>
    <j2se version="1.5+" initial-heap-size="32m" max-heap-size="128m" />
    <property name="jnlp.versionEnabled" value="false"/>
    $dependencies
 </resources>
 <application-desc main-class="$mainClass">
 </application-desc>
</jnlp>

Thanks.

PS: The project I'm using is from an example on Shaun Abram's website, here: http://www.shaunabram.com/swing-webstart-maven-example/. It was designed to interface with tomcat and run on a server but I feel like I should be able to get this to work locally. I'm just using the SwingWebstartMaven-Client branch and ignoring the SwingWebstartMaven-Web branch.

PPS: I feel like I should be able to rename the package structure, but for some reason I can't. Whenever I try replacing shaunabram with my last name in the directory structure, the package declaration in my java file, and in the pom.xml file, it complains with:

[ERROR]   The project com.kothur.swingwebstartmaven:SwingWebstartMaven-Client:1.0 (/media/reivei/New Volume/Project Files/SwingWebstartMaven/SwingWebstartMaven-Client/pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM: Failure to find com.kothur.swingwebstartmaven:SwingWebstartMaven:pom:1.0 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced and 'parent.relativePath' points at wrong local POM @ line 6, column 13 -> [Help 2]

EDIT: The problem is identical to this one: I am not able launch JNLP applications using "Java Web Start"? except on an Ubuntu machine. I'm having difficulty understanding how the author's solution would translate over to Ubuntu (I tried setting JAVAWS_HOME to my jre bin and rerunning javaws but it gave me the same problem (i.e. the Java 6 splash screen starts and then stops with no program to be found)). Double-clicking launch.jnlp runs it in Java 7 (not what I want) and spits out

"Error: Unable to load resource: http://localhost:8080/SwingWebstartMaven-Web/webstart/launch.jnlp." 

After that point, I tried a few other things. The primary pom.xml had the tomcat plugin, which I wasn't using, so I tried deleting it, which didn't do anything. I then tried actually creating a tomcat server and putting the project folder in /var/lib/tomcat7/webapps/. This also effected no change in the error.

No correct solution

OTHER TIPS

Read up on what Web Start actually does; it's a mechanism for reading a descriptor (e.g., the filled-in template.vm) and downloading and launching a regular Java application from it (as opposed to an applet). If you're running from the command line and already have the jar, it's redundant. If you really want to play with it, you need to edit template.vm into a valid JNLP descriptor file that points at the local codebase and then use javaws heet.jnlp. See the man page for javaws and the links it contains.

As for your Maven problem, it appears that you don't have the referenced parent POM installed, and so Maven doesn't know what to inherit from. You'll need to perform the same changes on the parent POM, install, and then work on the child POM.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top