简体   繁体   中英

java.lang.NoClassDefFoundError with jar file in terminal

In Eclipse, I wrote a Java class Test with a main() function. The project in which is defined the class, I added the jar file bcprov-jdk15on-151.jar (I am using the library BouncyCastle).

In Eclipse, there is no problem and my program runs normally. But when I try to do it in a terminal, I get an exception.

After checking SO I found a similar post: NoClassDefFoundError while running a java program in terminal from IDE but the solution given doesn't work.

To illustrate my case, in the directory C:\\Docs\\workspace\\Terminal\\bin\\ I have the file Test.class . If I run java Test I get Exception in thread "main" java.lang.NoClassDefFoundError: org.bouncycastle.math.ec.ECFieldElement .

If I run java -cp bcprov-jdk15on-151.jar Test (I put the .jar in the same directory to simplify) I get Error: Could not find or load main class Test so it seems that the dependency error is solved but another one occurs.

What am I doing wrong? Just to give the structure of my .java file:

import java.io.*;
   ...
public class Test {

    ... local methods ...

   public static void main(String[] args) {
       ...
   }
}

Thanks in advance.

Try this, you forgot to include current path "."

 java -cp ".;bcprov-jdk15on-151.jar" Test

Hope it help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM