Lucas_Santos
Lucas_Santos

Reputation: 4740

Class Not Found in my Jar File

I have the following code in a HTML page

        <applet code="com.griaule.fingerprintsdk.appletsample.FormMain"
            archive="SignedFingerprintSDKJava.jar, AbrirAplicativoAssinado.jar"
            width="515" height="560">
        </applet>

When I run my html page, a got an error that says, "ClassNotFoundException, FormMain.class"

I run jarscan and I found the class FormMain in my jar file.

What happened ?

This is how I generate my jar file

jar cvf C:\Users\lucas\desktop\AbrirAplicativo.jar C:\Users\lucas\workspace\applet-chave\bin\com\griaule\fingerprintsdk\appletsample\AppletInstaller.class C:\Users\lucas\workspace\applet-chave\bin\com\griaule\fingerprintsdk\appletsample\ColorPane.class C:\Users\lucas\workspace\applet-chave\bin\com\griaule\fingerprintsdk\appletsample\FormMain.class C:\Users\lucas\workspace\applet-chave\bin\com\griaule\fingerprintsdk\appletsample\FormOptions.class C:\Users\lucas\workspace\applet-chave\bin\com\griaule\fingerprintsdk\appletsample\Util.class 

Generate keys

keytool -genkey -dname "cn=AbrirAplicativoApplet, ou=XXX, o=XXX, l=São Paulo, s=SP c=BR" -alias AbrirAplicativoAppletKey -keystore C:\ChaveAbrirAplicativoApplet -storepass 123456 -validity 7300

Assign Jar File

jarsigner -keystore C:\users\lucas\desktop\ChaveAbrirAplicativoApplet -storepass 123456 -signedjar "C:\Users\lucas\Desktop\AbrirAplicativoAssinado.jar" "C:\Users\lucas\Desktop\AbrirAplicativo.jar" AbrirAplicativoAppletKey

Exporting Certificate

keytool -export -keystore C:\users\lucas\desktop\ChaveAbrirAplicativoApplet -alias AbrirAplicativoAppletKey -file C:\users\lucas\desktop\CertificadoAbrirAplicativoApplet.x509

Verifying Assign

keytool -import -alias AbrirAplicativoAppletKey -file C:\CHAVES\CertificadoAbrirAplicativoApplet.x509

Maybe my problem are in the PolicyTool

When I try to put a new policy entry I got the following error

java.net.MalformedURLException: no protocol: AbrirAplicativoAssinado.jar

but how can I put a URL in this field, if my jar file are in my desktop ?

I try to put http://localhost/AbrirAplicativoAssinado.jar but occurs a new error

There is not a public key for the alias AbrirAplicativoAppletKey.

Upvotes: 0

Views: 3931

Answers (2)

MvG
MvG

Reputation: 60908

OK the “class not found” should have nothing to do with signing. I take it that the jar files reside in the same directory as the html file?

There might be a problem with the way you list multiple archives. You might try the following approaches:

  • Omit the , from the archive list, leaving just the space.
  • Replace the , (including the space) by either : or ;.
  • Create a jar file which only contains a manifest, and in that manifest add a Class-Path property listing the other two archives, separated by a space. Use that file as the archive= parameter.
  • Modify one of your jar files to reference the other in the Class-Path property of its manifest, and only list that one in the archive= parameter.

It also apepars as if the way you build yor jar file, all the class files would be placed in the root directory of the file, without internal directory structure. The directory structure in the jar file has to match the package structure of your classes, i.e. the package lines in your source code, and also the code= parameter of your applet tag.

In order to create the directory structure inside your jar file, change directory to C:\Users\lucas\workspace\applet-chave\bin and then execute jar cvf C:\Users\lucas\desktop\AbrirAplicativo.jar com to add the whole directory com to the archive.

Upvotes: 1

user177800
user177800

Reputation:

You are specifying FormMain somewhere on your .html page when what you should be specifying is com.griaule.fingerprintsdk.appletsample.FormMain

All that signing stuff you put in your question is pretty irrelevant to a ClassNotFoundException.

I am not sure you are building the .jar correctly either, it is probably including your user path as well as the Eclipse working directory in the .jar. It would be better to take the time to set up Maven to build the .jar or at least use the tool built into Eclipse to export the .jar, that way you are sure it is being built correctly. Doing it by hand is open to all kinds of mistakes.

Upvotes: 0

Related Questions