Java Security Class Couldn't be found

26,915

Solution 1

I don't know if this is relevant to your problem but I was experiencing the exact same behavior due to versions of the JCE Policy files I was using.

Using the proper Unlimited Strength Cryptography Extenstions solved this issue for me. I believe I might have accidentally installed the extensions for Java 7 as opposed to 6. (I was using Java 6 for compilation)

For a windows machine, they should be installed in the jre/lib/security folder of your installed JDK, for example: c:\program files\Java\jdk1.6.0_33\jre\lib\security

Solution 2

The class should be located in the jce.jar file. This has to be on the classpath. Double check your classpath parameters which should be either the -cp parameter if you start the application without the -jar option xor the Class-Path entry in the jars manifest if you use java -jar myapp.jar to start you program


You found a common WTF ;) - that's a widely unknown rule: if you start you app with the -jar option, then the -cp option and the CLASSPATH environment are ignored. Then the classpath must specified inside the Manifest only.

Quick workaround - assuming, you "main class" is named com.example.App, then start the application like this:

java -cp jce.jar com.example.App

Solution 3

We had the permissions of our files only set to be read only by root and gave us a similar error.
Change permissions and things worked!

$ pwd
/usr/lib/jvm/java/jre/lib/security
$ ls -l
total 128
-rw-r--r--. 1 root root 2177 Mar 1 2013 blacklist
-rw-r--r--. 1 root root 84029 Sep 30 18:01 cacerts
-rw-r--r--. 1 root root 2253 Mar 1 2013 java.policy
-rw-r--r--. 1 root root 11804 Mar 1 2013 java.security
-rw-r--r--. 1 root root 109 Mar 1 2013 javaws.policy
-rw-r--r--. 1 root root 2481 Sep 16 16:50 local_policy.jar
-rw-r--r--. 1 root root 0 Mar 1 2013 trusted.libraries
-rw-r--r--. 1 root root 1924 Jul 18 17:42 truststore-epicinterbld.pem
-rw-r--r--. 1 root root 2465 Sep 16 16:50 US_export_policy.jar

Share:
26,915
Swine1973
Author by

Swine1973

Updated on June 16, 2020

Comments

  • Swine1973
    Swine1973 almost 4 years

    When launching my program the next error pops out

    java.lang.NoClassDefFoundError: Could not initialize class javax.crypto.SunJCE_b

    which means this class is missing although I've found this class manually, works via jar/ide but doesn't works prefectly via service.

    Maybe I need to make a few modifications? but which? Thanks in advance