我在编写外部jar和源代码时遇到问题。我的.java文件和外部jar驻留在同一目录中。这是我的makefile:
JFLAGS = -g
JC = javac -cp ${CLASSPATH}
.SUFFIXES: .java .class
.java.class:
$(JC) $(JFLAGS) $*.java
CLASSPATH = *.jar
CLASSES = \
AESCBC.java
default: classes
classes: $(CLASSES:.java=.class)
clean:
$(RM) *.class
编译成功。但是,当我运行java AESCBC
时,我收到以下错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/bouncycastle/jce/provider/BouncyCastleProvider
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2693)
at java.lang.Class.privateGetMethodRecursive(Class.java:3040)
at java.lang.Class.getMethod0(Class.java:3010)
at java.lang.Class.getMethod(Class.java:1776)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.jce.provider.BouncyCastleProvider
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
答案 0 :(得分:1)
您需要在运行类时指定依赖项。假设您的类未编译为JAR,您将按如下方式运行它:
java -cp [在此处放置您的相关信息] AESCBC