问题描述
我无法运行一个在IntelliJ IDEA中正常工作的java程序。我在运行相同的代码时(在删除软件包后),得到的错误如下
I am having trouble running a java program that works fine in the IntelliJ IDEA ide. The error I get when I run the same code (after removing the package ..) as follows
Exception in thread "main" java.lang.NoClassDefFoundError: fcrypt
Caused by: java.lang.ClassNotFoundException: fcrypt
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
我在main方法中所做的就是创建一个主类的实例并调用几个方法。只有头部和main方法的代码如下
All I'm doing in the main method is creating an instance of the main class and calling the several methods. The code with just the headers and the main method as below
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.util.encoders.Base64;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.io.*;
import java.security.*;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.Arrays;
/**
* Created by Aditya Rao on 05/02/14.
*/
public class fcrypt {
private static final String RSA_NONE_PKCS1PADDING = "RSA/None/PKCS1Padding";
static {
Security.addProvider(new BouncyCastleProvider());
}
....
public static void main (String[] args) throws Exception {
if (args.length != 5) {
System.out.print("Invalid parameters. ");
printUsage();
System.exit(1);
}
if (!(args[0].equals("-e") | args[0].equals("-d"))) {
System.out.print("Please specify usage. ");
printUsage();
System.exit(1);
}
fcrypt f = new fcrypt();
String[] inputs = Arrays.copyOfRange(args, 1, args.length);
if (args[0].equals("-e"))
f.encryptAndSign(inputs);
else
f.verifyAndDecrypt(inputs);
}
}
我缺少这里的东西吗?
EDIT 使用以下命令编译和运行此程序
EDIT I compile and run this program with the following commands
javac -cp libs/bcprov-jdk15on-150.jar fcrypt.java
java -cp libs/bcprov-jdk15on-150.jar fcrypt <args>
推荐答案
您必须添加工作目录
Unix的语法:
java -cp ".:libs/bcprov-jdk15on-150.jar" fcrypt
注释元素用:
分隔。
:
java -cp ".;libs/bcprov-jdk15on-150.jar" fcrypt
注释元素用;
分隔。
Java代码样式建议类名以大写字母开头。因此应该是在
。 FCrypt.java
中定义的类FCrypt
Java code style suggests class names to start with a capital letter. So it should be class FCrypt
defined in FCrypt.java
.
这篇关于在IDE中在终端中运行java程序时发生NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!