错误,包括充气城堡提供者 [英] Error including bouncycastle provider
问题描述
我需要在项目中使用bouncycastle provider
库.
I need to use bouncycastle provider
library in my project.
我已经将它包含在gradle项目中.
I have included it the gradle project.
apply plugin: 'application'
sourceCompatibility = '1.6'
version = '1.0.0'
mainClassName = 'path.to.main.file'
dependencies {
compile "org.mariadb.jdbc:mariadb-java-client:+"
compile "org.bouncycastle:bcprov-jdk16:+"
compile "commons-codec:commons-codec:+"
testCompile "junit:junit:+"
}
项目构建成功.但是当我尝试运行该项目时.无法找到bouncycastle
The project build successfully. But when I try to run the project. It is not able to find the bouncycastle
Exception in thread "main" java.lang.NoClassDefFoundError: org/bouncycastle/jce/provider/BouncyCastleProvider
at com.example.Server.main(Server.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.jce.provider.BouncyCastleProvider
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 6 more
我该如何解决?
推荐答案
您可能无法正确运行应用程序.
如果仅使用java -jar foo.jar
运行创建的JAR,则会在运行时错过所有依赖项.
您必须将这些依赖项添加到类路径中.
You probably don't run your application correctly.
If you just run the created JAR with java -jar foo.jar
, you miss all dependencies at runtime.
You have to add those dependencies to your classpath.
您可以通过多种方式执行此操作.
例如您可以创建一个胖的JAR,使用一些Gradle插件将所有依赖项重新打包到最终的JAR中(有几个,但是我根本不喜欢这种解决方案,因此我无法推荐其中一个).
或者您可以e. G.应用application
插件,则可以使用run
任务正确运行您的应用程序,并使用distZip
任务获取与您的应用程序,所有依赖项和启动脚本的现成的分发ZIP,这些脚本可以正确设置运行时类路径.
或者可以. G.用java -cp foo.jar;other.jar;another.jar your.main.Class
手动完成.
You have various ways to do this.
E. g. you can create a fat JAR where all dependencies are repacked into the final JAR with some Gradle plugin (there are several, but I don't like this solution at all, so I cannot recomment one).
Or you can e. g. apply the application
plugin, then you can use the run
task to correctly run your application and use the distZip
task to get a ready-made distribution ZIP with your app, all dependencies and start scripts that correctly set the runtime classpath.
Or you can e. g. manually do it with java -cp foo.jar;other.jar;another.jar your.main.Class
.
这篇关于错误,包括充气城堡提供者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!