Java JUnit5控制台Launcher NoClassDefFoundError

Java JUnit5控制台Launcher NoClassDefFoundError,java,junit,command-line,classpath,junit5,Java,Junit,Command Line,Classpath,Junit5,我的测试文件使用Commons IO库: import org.apache.commons.io.FileUtils; ... @Test public void testExampleEvalOutput_dataset() throws IOException { File file1 = FileUtils.getFile(pathToProject + pathToExampleResults + "exampleEvalOutput_dataset.csv"); F

我的测试文件使用Commons IO库:

import org.apache.commons.io.FileUtils;
...
@Test
public void testExampleEvalOutput_dataset() throws IOException {

    File file1 = FileUtils.getFile(pathToProject + pathToExampleResults + "exampleEvalOutput_dataset.csv");
    File file2 = FileUtils.getFile(pathToProject + pathToYourResults + "exampleEvalOutput_dataset.csv");
    assertEquals(true, FileUtils.contentEquals(file1, file2));
}
当我从Eclipse运行时,测试工作正常

正在尝试从命令行运行。编译测试文件:

$mkdir out

Commons IO jar与JUnit ConsoleLancher jar一起位于
lib
目录中

$javac-d out-cp“lib/*”path/to/ExampleEvalTests.java

编辑作品

但是,在运行时不会拾取库:

$java-jar-lib/junit-platform-console-standalone-1.3.2.jar-cp-lib:out/--扫描类路径

JUnit Vintage:ExampleEvalTests:testExampleEvalOutput_dataset
MethodSource [className = 'org.company.test.ExampleEvalTests', methodName = 'testExampleEvalOutput_dataset', methodParameterTypes = '']
=> java.lang.NoClassDefFoundError: org/apache/commons/io/FileUtils
   org.company.test.ExampleEvalTests.testExampleEvalOutput_dataset(ExampleEvalTests.java:27)
   java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
   java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   java.base/java.lang.reflect.Method.invoke(Method.java:564)
   org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
   org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
   org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
   org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
   org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
   [...]
目录结构:

lib
组织机构
公司
测试
输出


如何让可执行文件in
out
拾取
lib

基于@Sormuras注释,添加用于类路径的特定jar。但是,如果使用了许多依赖项,这似乎不是一个理想的解决方案:


$java-jar-lib/junit-platform-console-standalone-1.3.2.jar-cp-lib/commons-io-2.6.jar:out——扫描类路径

请枚举位于“lib”目录中的所有jar文件。比如:
java-jar-cp lib/apache-commons-x.jar:另一个工具。jar:out——扫描类路径
@Sormuras,谢谢@Sormuras通配符JAR可以通过如下的-cp参数加载到java类路径:
java-cp.;lib\*“org.junit.platform.console.consoleLancher——扫描类路径
。不确定为什么junit的
-cp
不能以相同的方式工作。
JUnit Vintage:ExampleEvalTests:testExampleEvalOutput_dataset
MethodSource [className = 'org.company.test.ExampleEvalTests', methodName = 'testExampleEvalOutput_dataset', methodParameterTypes = '']
=> java.lang.NoClassDefFoundError: org/apache/commons/io/FileUtils
   org.company.test.ExampleEvalTests.testExampleEvalOutput_dataset(ExampleEvalTests.java:27)
   java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
   java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   java.base/java.lang.reflect.Method.invoke(Method.java:564)
   org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
   org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
   org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
   org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
   org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
   [...]