[英]Cannot recognise “import org.junit.Assert” in a java file
I have this problem that I cannot understand why it doesn't exist. 我有一个问题,我不明白为什么它不存在。
Basically, when I compile the following command: 基本上,当我编译以下命令时:
C:\Users\Bill\My Documents\Antbook\ch04> javac -d build\test test\org\example\antbook\junit\SimpleTest.java
It gives me an error saying: "java:4 error: Package org.junit does not exist" and same with line 5. Plus, on line 9, it cannot find the "@Test". 它给我一个错误,说:“ java:4错误:包org.junit不存在”,与第5行相同。另外,在第9行,它找不到“ @Test”。
Heres, the code: 代码如下:
package org.example.antbook.junit;
//import JUnit4 classes:
import static org.junit.Assert.*;
import org.junit.Test;
public class SimpleTest
{
@Test
public void testSomething()
{
assertTrue("MULTIPLICATION???", 4 == (2 * 2));
}
}
Can anyone give any suggestions? 任何人都可以提出建议吗? Am I meant to copy the jar files containing the Junit classes in to a directory?
我是否要将包含Junit类的jar文件复制到目录中?
Thanks. 谢谢。
The best way is to put it in a dedicated folder for your libraries (ie. jar files) and include that directory in the classpath when you execute javac
on the command line. 最好的方法是将其放在库的专用文件夹(即jar文件)中,并在命令行上执行
javac
时将该目录包括在类路径中。 In this case, if you are only using one jar file junit-4.11.jar
, then this will work. 在这种情况下,如果仅使用一个jar文件
junit-4.11.jar
,那么它将起作用。
C:\Users\Bill\My Documents\Antbook\ch04> javac -cp yourLibDir\junit-4.11.jar -d build\test test\org\example\antbook\junit\SimpleTest.java
If you have more jar files, use a *
to include through all the jar files in a dir on the classpath: 如果您有更多的jar文件,请使用
*
来将所有jar文件包括在类路径的dir中:
javac -cp yourLibDir\*
You need to add junit-latestversion.jar under your lib folder and include it in your class path 您需要在lib文件夹下添加junit-latestversion.jar并将其包含在类路径中
Here is the way to add classpath from command line 这是从命令行添加类路径的方法
java -cp jar1:jar2:jar3:dir1:. java -cp jar1:jar2:jar3:dir1:。 HelloWorld
你好,世界
Here is thje link 这是链接
http://stackoverflow.com/questions/2096283/including-jars-in-classpath-on-commandline-javac-or-apt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.