无法找到 Java 安全类
启动我的程序时,会弹出下一个错误
java.lang.NoClassDefFoundError:无法初始化类 javax.crypto.SunJCE_b
,这意味着该类丢失,尽管我手动找到了该类,可以通过jar/ide工作,但不能通过服务完美工作。
也许我需要做一些修改?但哪个? 提前致谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我不知道这是否与您的问题相关,但由于我使用的 JCE 策略文件版本,我遇到了完全相同的行为。
使用正确的 无限强度加密扩展 为我解决了这个问题。我相信我可能不小心安装了 Java 7 的扩展,而不是 6。(我使用 Java 6 进行编译)
例如,对于 Windows 计算机,它们应该安装在已安装的 JDK 的 jre/lib/security 文件夹中: c:\program files\Java\jdk1.6.0_33\jre\lib\security
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
该类应位于
jce.jar
文件中。这必须位于类路径上。仔细检查您的类路径参数,如果启动应用程序时不使用-jar
选项,则该参数应该是-cp
参数,或者是Class如果您使用 java -jar myapp.jar 启动程序,则 jar 清单中的 -Path
条目您发现了一个常见的 WTF ;) - 这是一个广泛未知的规则:if< /strong> 使用
-jar
选项启动应用程序,然后使用-cp
选项和CLASSPATH
环境被忽略。 然后类路径必须仅在清单内指定。快速解决方法 - 假设您的“主类”名为
com.example.App
,然后像这样启动应用程序: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 theClass-Path
entry in the jars manifest if you usejava -jar myapp.jar
to start you programYou found a common WTF ;) - that's a widely unknown rule: if you start you app with the
-jar
option, then the-cp
option and theCLASSPATH
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:我们将文件的权限设置为只能由 root 读取,并给了我们类似的错误。
更改权限并且一切正常!
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!
启动时检查正在使用哪个 jre,并确保 jre/lib/ext 文件夹包含 sunjce_provider.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.
我删除了/Library/Java/VirtualMachine(有osx)中的各种旧的JDK,重新启动android studio后错误消失了,但我不想再次设置jdk。也许它对其他人有帮助。
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.
这是 JRE 版本的问题,它应该指向与程序使用的 jre 版本相同的版本,它查找“jre/lib/security”应该位于程序的同一 jdk 下
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