Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add 'all-permissions' to manifest file with Maven in combination with Webstart Maven plugin?

I recently started experimenting with Maven. As a test, I'm trying to create a simple JavaFX8 webstart application.

For this I used the JavaFX sample under the Maven category in Netbeans 8. This gives me a simple HelloWorld application:

HelloWorld

I have added a new profile to my pom.xml file called 'jnlp'. This to be able to create a JNLP file (using the webstart maven plugin) when building the project.

....
<profiles>
    <profile>
        <id>jnlp</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>webstart-maven-plugin</artifactId>
                    <version>1.0-beta-6</version>
                    <dependencies>
                        <dependency>
                            <groupId>org.codehaus.mojo</groupId>
                            <artifactId>webstart-pack200-impl</artifactId>
                            <version>1.0-beta-6</version>
                        </dependency>
                        <dependency>
                            <groupId>org.codehaus.mojo</groupId>
                            <artifactId>keytool-api-1.7</artifactId>
                            <version>1.5</version>
                        </dependency>
                    </dependencies>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>jnlp</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <codebase>http://(my_url)/maven/</codebase> //replaced the url obviously :)
                        <jnlp>
                            <mainClass>com.mycompany.mavenprojecthelloworld.MainApp</mainClass>
                        </jnlp>
                        <pack200>
                            <enabled>false</enabled>
                        </pack200>
                        <sign>
                            <keystore>${project.basedir}/src/main/jnlp/mykeystore</keystore>
                            <keypass>mykeypass</keypass>
                            <storepass>mystorepass</storepass>
                            <alias>myalias</alias>
                            <verify>true</verify>
                        </sign>
                        <verbose>true</verbose>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

When I build this, it generates a launch.jnlp file and a mavenprojectHelloWorld-1.0-SNAPSHOT.jar file in the /target/jnlp directory. I double checked with jarsigner to check if my jar file was correctly signed. This was the output:

jarsigner

I copied the launch.jnlp and mavenprojectHelloWorld-1.0-SNAPSHOT.jar file to my webhost (http://(my_url)/maven) and started the HelloWorld app by launching the JNLP file. However, when I do that, I get a message 'Java Application Blocked' window and an 'Application Error' afterwards:

java application blocked

application error

The Java console told me the following:

java.lang.SecurityException: JAR manifest requested to run in sandbox only: http://(my_url)/maven/mavenprojectHelloWorld-1.0-SNAPSHOT.jar
at com.sun.deploy.security.DeployManifestChecker.verify(Unknown Source)
at com.sun.deploy.security.DeployManifestChecker.verify(Unknown Source)
at com.sun.javaws.security.AppPolicy.grantUnrestrictedAccess(Unknown Source)
at com.sun.javaws.security.JNLPSignedResourcesHelper.checkSignedResourcesHelper(Unknown Source)
at com.sun.javaws.security.JNLPSignedResourcesHelper.checkSignedResources(Unknown Source)
at sun.plugin2.applet.JNLP2Manager.prepareLaunchFile(Unknown Source)
at sun.plugin2.applet.JNLP2Manager.loadJarFiles(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

After checking the manifest file from my JAR file, I noticed that the permissions and codebase tags were missing. Now I want to add those through maven. After some reading and searching, I found a similar question here: Simpliest way to add an attribute to a jar Manifest in Maven. So I tried to add the following to my pom.xml:

<project>
...
<build>
    ...
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.6</version>
        <configuration>
            <archive>
                <manifestEntries>
                    <Permissions>all-permissions</Permissions>
                    <Codebase>*</Codebase>
                </manifestEntries>
            </archive>
         </configuration>
     </plugin>
...
</build>
</project>

After building again, I checked the manifest file to view my changes, but it seems that manifest file was not changed. I still receive the following:

Manifest-Version: 1.0
Permissions: sandbox
JavaFX-Version: 8.0
Created-By: JavaFX Packager
Main-Class: com.mycompany.mavenprojecthelloworld.MainApp

I must be doing something wrong or missing something. When reading up on creating JNLP files with Maven and how to edit the manifest file, I noticed a lot of old information on the web that wasn't valid anymore. So it kinda got me confused about what to do know. I hope someone can point me in the right direction.

Update 31/08/2015:

Forgot to mention I'm using a velocity template, you can find the template below:

<?xml version="1.0" encoding="utf-8"?>
<jnlp
    spec="1.0+"
    codebase="$jnlpCodebase"
    href="$outputFile">

    <information>
        <title>$project.name</title>
        <vendor>$project.Organization.Name</vendor>
        <description>$project.Description</description>
    </information>
    <resources>
        <j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se" />
        $dependencies
    </resources>
    <security>
        <all-permissions/>
    </security>
    <applet-desc width="1024" height="768" main-class="com.javafx.main.NoJavaFXFallback" name="$project.name">
        <param name="requiredFXVersion" value="8.0+"/>
    </applet-desc>
    <jfx:javafx-desc width="1024" height="768" main-class="$mainClass"  name="$project.name" />
    <update check="background"/>
</jnlp>

Another thing I noticed is that, building with the JNLP profile works fine. But running the project with the JNLP profile (in NetBeans) seems to fail (running with default profile works thou). I don't know if this has anything to do with this issue or not (as I'm not familiar with Maven yet). However, this is the output in NetBeans when trying to run the project:

....
--- exec-maven-plugin:1.2.1:exec (default-cli) @ mavenprojectHelloWorld ---
Error: Could not find or load main class com.mycompany.mavenprojecthelloworld.MainApp
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 1.308s
Finished at: Thu Aug 27 12:00:03 CEST 2015
Final Memory: 8M/155M
------------------------------------------------------------------------
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default-cli) on project mavenprojectHelloWorld: Command execution failed. Process exited with an error: 1 (Exit value: 1) -> [Help 1]
like image 540
Perneel Avatar asked Aug 25 '15 15:08

Perneel


1 Answers

I went through the Webstart Maven Plugin information again and it appears that I have to use <updateManifestEntries> instead, so I adjusted my code as following:

<configuration>
    <codebase>...</codebase>
    <jnlp>
        <mainClass>com.mycompany.mavenprojecthelloworld.MainApp</mainClass>
    </jnlp>
    <pack200>
        <enabled>false</enabled>
    </pack200>
    <sign>
        ...
    </sign>
    <verbose>true</verbose>
    <updateManifestEntries>
        <Application-Name>HelloWorld</Application-Name>
        <Trusted-Library>true</Trusted-Library>
        <Permissions>all-permissions</Permissions> 
        <Codebase>*</Codebase>
        <Trusted-Only>true</Trusted-Only> 
    </updateManifestEntries>
 </configuration>

By looking for the <updateManifestEntries> I also stumbled on this question which helped me further as well: New <updateManifestEntries> entries of webstart-maven-plugin breaks the application

like image 77
Perneel Avatar answered Oct 13 '22 23:10

Perneel