繁体   English   中英

为什么需要在intellij中添加类路径?

[英]Why do I need to add classpath in intellij?

我试图将此类添加到我的代码中:

import org.junit.runner.JUnitCore;
import org.junit.runner.Request;
import org.junit.runner.Result;

public class SingleJUnitTestRunner {
    public static void main(String... args) throws ClassNotFoundException {
        String[] classAndMethod = args[0].split("#");
        Request request = Request.method(Class.forName(classAndMethod[0]),
                classAndMethod[1]);

        Result result = new JUnitCore().run(request);
        System.exit(result.wasSuccessful() ? 0 : 1);
    }
}

然后我得到了这个错误:

在此处输入图片说明

即使我的Gradle包含JUnit 4.12

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'

我怎样才能解决这个问题?
“添加到课程路径”是什么意思? 我曾经在Eclipse中看到过它。 不在IntelliJ中

请尝试使用:

dependencies {
    compile group: 'junit', name: 'junit', version: '4.12'

代替:

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'

如果您在IntelliJ中将项目设置为Gradle项目,则类路径应与gradle文件同步。 您可以在文件->项目结构->模块->依赖关系->加号按钮( http://i.imgur.com/QLS6JRH.png )中配置IntelliJ依赖项

类路径由编译器使用。 它需要知道在哪里可以找到JUnitCore以便进行编译。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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