maven error: package org.junit does not exist maven error: package org.junit does not exist java java

maven error: package org.junit does not exist


Ok, you've declared junit dependency for test classes only (those that are in src/test/java but you're trying to use it in main classes (those that are in src/main/java).

Either do not use it in main classes, or remove <scope>test</scope>.


I fixed this error by inserting these lines of code:

<dependency>  <groupId>junit</groupId>     <!-- NOT org.junit here -->  <artifactId>junit-dep</artifactId>  <version>4.8.2</version>  <scope>test</scope></dependency>

into <dependencies> node.

more details refer to: http://mvnrepository.com/artifact/junit/junit-dep/4.8.2


if you are using Eclipse watch your POM dependencies and your Eclipse buildpath dependency on junit

if you select use Junit4 eclipse create TestCase using org.junit package but your POM use by default Junit3 (junit.framework package) that is the cause, like this picture:

see JUNIT conflict

Just update your Junit dependency in your POM file to Junit4 or your Eclipse BuildPath to Junit3