Trouble integrating BouncyCastle Jar

江枫思渺然 提交于 2019-12-30 08:13:33

问题


Okay, I'll say now that I know very little about Java. I was given the Bouncy Castle Jar and told that would contain what I needed to do this assignment. The Jar file is bcprov-jdk15on-147.jar. I'm also doing this on a Unix machine maintained by my school, so I can't go in and play with all of the Java files.

When I compile my class using Javac (specifically I use the command javac -classpath bcprov-jdk15on-147.jar encrypt.java), it compiles without error, but when I go to run the program afterward using the command java encrypt, I get this error message:

Exception in thread "main" java.lang.NoClassDefFoundError: org/bouncycastle/jce/provider/BouncyCastleProvider
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.jce.provider.BouncyCastleProvider
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

My Jar file is located in my main folder with all of my other files, just in case it has to go somewhere special and that's what I didn't do.

When I do java -classpath bcprov-jdk15on-147.jar encrypt this is the error I get:

    Exception in thread "main" java.lang.NoClassDefFoundError: encrypt
Caused by: java.lang.ClassNotFoundException: encrypt
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

Why am I having trouble running the compiled program?


回答1:


Type this for running the program:

java -classpath bcprov-jdk15on-147.jar:. encrypt

That's because your program also needs to have any libraries it uses as part of the classpath at the time of running, not only at compile time.



来源:https://stackoverflow.com/questions/10134161/trouble-integrating-bouncycastle-jar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!