为什么我需要在intellij中添加类路径?
Why do I need to add classpath in intellij?
我尝试将此 class 添加到我的代码中:
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'
我该如何解决这个问题?
"adding to class path" 是什么意思?我曾经在 Eclipse 中看到过它。不在 IntelliJ.
中
请尝试使用:
dependencies {
compile group: 'junit', name: 'junit', version: '4.12'
而不是:
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
如果您在 IntelliJ 中的项目设置为 Gradle 项目,则类路径应与您的 gradle 文件同步。您可以在 File -> Project Structure -> Modules -> Dependencies -> Plus Button (http://i.imgur.com/QLS6JRH.png)
配置 IntelliJ 依赖项
类路径由编译器使用。它需要知道在哪里可以找到 JUnitCore 以便它可以编译。
我尝试将此 class 添加到我的代码中:
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'
我该如何解决这个问题?
"adding to class path" 是什么意思?我曾经在 Eclipse 中看到过它。不在 IntelliJ.
请尝试使用:
dependencies {
compile group: 'junit', name: 'junit', version: '4.12'
而不是:
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
如果您在 IntelliJ 中的项目设置为 Gradle 项目,则类路径应与您的 gradle 文件同步。您可以在 File -> Project Structure -> Modules -> Dependencies -> Plus Button (http://i.imgur.com/QLS6JRH.png)
配置 IntelliJ 依赖项类路径由编译器使用。它需要知道在哪里可以找到 JUnitCore 以便它可以编译。