Search code examples
javanetbeansappletsignself-signed

How to self-sign an applet with NetBeans?


In the previous months I developed a sandbox applet for an academic project. Due to the Java 1.7.51 security restrictions to applets, I have been trying to self-sign my applet with the hope that it can comply or overcome JRE's requisites for applets.

I'm using NetBeans and I have taken as a point of departure some links that show how to self-sign a jar file. Unfortunately, I haven't been able to get it working.

I have tried to add the following instructions on the build.xml file:

<target name="-post-jar" depends="signing_procedure">
</target>

<target name="signing_procedure" depends="">
    <echo message="Signing ${dist.dir}/MyFile.jar"/>
    <exec dir="C:/Program Files/Java/jdk1.7.0_25/bin/" executable="jarsigner.exe">
        <arg value="-verbose" />
        <arg value="-keystore" />
        <arg value="C:/Program Files/Java/jdk1.7.0_25/bin/MyKeyStore.jks" />
        <arg value="-storepass" />
        <arg value="mystorepass" />
        <arg value="-keypass" />
        <arg value="mykeypass" />
        <arg value="C:/Users/Charles/Documents/ProjectsFolder/MyProject/dist/MyFile.jar" />
        <arg value="MyAlias" />
    </exec>
</target>

I receive the following error message:

Execute failed: java.io.IOException: Cannot run program "jarsigner.exe": error=2, The specified file is not found

I would deeply thank you for your help, and much more if it is adressed to NetBeans!


Solution

  • I figured out how to do it. The following lines need to be added to the build.xml, under the tab Files of the corresponding project on NetBeans:

    <target name="-post-jar" depends="Signing Procedure">
    </target>
    
    <target name="Signing procedure" depends="">
        <echo message="Signing ${dist.dir}/MyAppet.jar..."/>
        <exec dir="${dist.dir}" executable="C:/Program Files/Java/jdk1.7.0_25/bin/jarsigner.exe">
            <arg value="-verbose" />
            <arg value="-keystore" />
            <arg value="C:/Program Files/Java/jdk1.7.0_25/bin/MyKeyStore.jks" />
            <arg value="-storepass" />
            <arg value="mystorepassword" />
            <arg value="-keypass" />
            <arg value="mykeypassword" />
            <arg value="C:/Users/Charles/Documents/MyNetBeansProjects/MyProject/dist/MyApplet.jar" />
            <arg value="MySelfSignatureAlias" />
        </exec>
    </target>
    

    I hope this is useful to other users!