The Problem

One of the key stages in compiling and deploying a J2ME application to a RIM Blackberry device is utilsing the JadTool to cryptographically sign your application JAR file and convert it to a Blackberry COD file

An error that has caught me out several times over the last year or so of BB development is this:

Jar to get signature is dist/blackberry/deploy/demo/unsigned/YW_INT.jar
java.lang.NoClassDefFoundError: sun/security/pkcs11/SunPKCS11
Caused by: java.lang.ClassNotFoundException: sun.security.pkcs11.SunPKCS11
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
Could not find the main class: com.sun.midp.jadtool.JadTool. Program will exit.

The error typically occurs when I either move development machines or upgrade my JDK - this is because the JDK is itself the cause of the problem.

The Solution

The problem is typically (in my cases) caused by attempting to sign a JAR when compiling with a 64 bit JDK. For some reason certain versions of the Sun JDKs don't include the required sun.security.pkcs11.SunPKCS11 package, and in particular none of the 64-bit versions I have used contain this package.

Accordingly the solution is rather simple: Just install a 32bit JDK along side (or instead) of your 64 bit JDK, and make sure you compile and sign the JAR/COD file with the 32 bit version.

I hope this helps, and if it does then please let me know!

Daniel

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Daniel Bryant (Director) | Tai-Dev Ltd www.tai-dev.co.uk - IT Consultancy Services Specialising in JEE, Web 2.0 and RDBMS