JNLP, Webstart, and Maven
Asked Answered
A

1

7

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.

Aground answered 6/8, 2013 at 4:41 Comment(10)
"Fails"? Did you also replace shaunabram in the package name of the class?Accustomed
I did, yes. My bad for not mentioning that; OP updated.Aground
If you downvote me, can you explain why? Is it the gratuitous code snippets or the fact that this is a really noobish question? What would be a better way to formulate the question?Aground
(I'm not downvoting, by the way.) The purpose of template.vm is that Java Web Start needs a descriptor file to tell it about the application it's supposed to launch (Java version required, where to find jars, etc.). template.vm is a Velocity template that gets filled in and sent to the Web Start loader. Have you simply tried using java on the program?Accustomed
Downvotes are expected; I just wanted to know why for future reference. It works fine with java--I just really want to run it as a webstart application.Aground
Up-Voted: I've spent last 2 days (and night) chasing bugs using the same combination (Swing, Maven and JNLP). I ended up rewriting the maven-webstart-plugin in ANT... Because there is no way to change manifest file in all dependencies. It seems all the support for JNLP in Maven is too simplistic for production use.Calends
Alas, I really wish I could do that. Unfortunately, the source code from which I'm deriving my primary application (tatool) uses Maven as its build tool and rewriting the whole thing would be pretty much impossible without breaking all of the dependencies. Could you maybe explain what you mean by there's no way to change the manifest file in all dependencies? Do you just mean it's hard to refactor when you're changing package names or something?Aground
@HeetK. I did it to update all the dependent jars with new manifest attributes "Permissions: all-permissions" and "Codebase: ${URL}" which were introduced around Java 7u25. For now they only cause warnings, but it might become an error in of future releases. Maven-webstart-plugin has a specific bug for it (and a patch already), but it hasn't been integrated yet.Calends
The Bug: jira.codehaus.org/browse/MWEBSTART-213Calends
Ah, okay. Your problem seems to be somewhat unrelated to mine. I've updated the OP with additional information (including a new directory structure and pom.xml files) if anyone wants to see the full project.Aground
A
3

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.

Accustomed answered 6/8, 2013 at 5:50 Comment(1)
Yeah, I realized what was wrong with the POM file about half an hour ago. Major derp moment. As for javaws... after adding in all of the old parent files and running javaws launch.jnlp, I run into the old problem of hitting the Java 6 splash animation, which runs for about 18 seconds before exiting. I'll update the OP with more relevant information in the morning.Aground

© 2022 - 2024 — McMap. All rights reserved.