3

I wrote a custom PKCS11 provider and now i want to user it via jarsigner.

My command :

jarsigner -verbose -keystore NONE -storetype PKCS11 -providerClass my.provider.class jar_to_sign_on.jar "key_name"

And i get the following error :

jarsigner error: java.lang.ClassNotFoundException: my.provider.class

This is because jarsinger can't find my provider .jar implementation.

When i put mt .jar in ...\Java\jdk1.8.0_31\jre\lib\ext it works perfectly.

My question is : There is a way to dynamically set my provider .jar ? (Like -providerPath in keytool)

DVarga
  • 21,311
  • 6
  • 55
  • 60
Saar peer
  • 817
  • 6
  • 21

2 Answers2

2

jarsigner has -J option that allows to pass its value right to the backing java process. The problem is that it doesn't allow spaces, so you need two such options to pass a classpath. Something like this should work:

jarsigner ... -J-cp -Jmylib.jar

Andrew Lygin
  • 6,077
  • 1
  • 32
  • 37
  • Hi, 10x. I get : Error: Could not find or load main class cp – Saar peer Jul 19 '16 at 05:49
  • Sorry, the correct version should be `jarsigner ... -J-cp -Jmylib.jar` to make the `java` command know that `cp` is an option, not a class name. – Andrew Lygin Jul 19 '16 at 05:53
  • Nice : Now i get the following : Error: Could not find or load main class sun.security.tools.jarsigner.Main – Saar peer Jul 19 '16 at 05:59
  • At least the option works. Unfortunately it overrides the options jarsigner passes to java, but that can be fixed. What JDK do you use? I think you need to add path to the JDK's `tools.jar` to `-Jmylib.jar` which contains the missing class. On my system it would be `-Jmylib.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0/Contents/Home/lib/tools.jar` – Andrew Lygin Jul 19 '16 at 06:15
  • 2
    I found a reasonable solution : I added -J-Djava.ext.dirs=my_jar_lib and it works. The downside is that i need to copy one jar from the ...\Java\jdk1.8.0_31\jre\lib\ext to mine .jar folder. – Saar peer Jul 19 '16 at 07:00
0

Java classpath allows specifying multiple jar files separated by ':'. In this case, you can use

-J-cp -J./mylib.jar:<path to tools.jar>tools.jar

Dymanuel
  • 1
  • 1