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
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
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
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
Check which jre is being used when you're launching and make sure the jre/lib/ext folder contains sunjce_provider.jar
Make sure you aren't using the extensions directory option. In the past when I used the extensions directory option instead of a classpath it was no longer able to load the Security libraries and policies. When I went back to using an explicit classpath the Security functionality resumed working.
I deleted various older JDKs in /Library/Java/VirtualMachine (got osx) and after restarting android studio the error was gone, but I hat to set the jdk again. Maybe it helps others.
This is issue with the JRE version, it should point to the same jre version as being used by the program, it looks for "jre/lib/security" should be under the same jdk of your program