开发者

running junit from command line with jar file

I have two java file, Point.java and PointTest.java. The work fine in eclipse but I'm trying to compile them through commandline

I downloaded the junit 4.8.2 jar file into the same directory as the .j开发者_如何学JAVAava files

I am currently trying this command to compile them but im getting errors

javac -cp junit-4.8.2.jar:. Point.java PointTest.java

I have tried the command with -cp as well. The first error is

 package org.junit does not exist

What am I doing wrong here? If I extract the jar file in the directory, then I am able to compile the java files correctly.

In case it helps, the first few import declarations in the test file are

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;


Could you verify if the name of the junit jar is correct. The default name is junit-4.8.2.jar and not junit.4.8.2.jar


Compile with the -verbose flag so you can see what the compiler is doing. It will print out the classpath.


I suggest looking at the examples in the javac page, particularly Separating Source Files and Class Files. Splitting out source, class files and libraries is common. See, for example, the Maven Standard Directory Layout and Sun Developers Network - Project Conventions. Most IDEs will encourage a similar layout.

Why not do the simple thing and have source files in the same directory as class files? For one thing, if you delete or rename a class, but forget to delete the class file, you can have source code that references the old class. There are a few other gotchas that most of us don't remember because no one puts classes and source files in the same directory.

If you are just experimenting with Java and JUnit I strongly recommend an IDE like Eclipse. For automated builds you might want to consider looking into Ant, Maven or Ivy, but for getting started an IDE has a smaller learning curve with a lot of extra benefits (code completion, debugging, a UI for reviewing JUnit test failures...).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜