Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven error: package org.junit does not exist

I'm trying to create the javadoc with maven and it fails. It also fails when doing the verify.

mvn verify 

I get the following error:

(...)     [INFO] -------------------------------------------------------------     [ERROR] COMPILATION ERROR :      [INFO] -------------------------------------------------------------     [ERROR] /home/miquel/creaveu/createOmegaMatrix/src/main/java/edu/url/salle/gtm/hnm/dataStructures/HFrame.java:[6,23] package org.junit does not exist     [ERROR] /home/miquel/creaveu/createOmegaMatrix/src/main/java/edu/url/salle/gtm/hnm/dataStructures/HFrame.java:[6,0] static import only from classes and interfaces     (···) 

In my pom.xml file I have the following lines:

<dependency>   <groupId>org.junit</groupId>   <artifactId>junit</artifactId>   <version>4.8.2</version>   <scope>test</scope> </dependency> 

and my local repository contains the junit jar file:

miquel@ubuntu:~/creaveu/createOmegaMatrix$ ls -l /home/miquel/.m2/repository/org/junit/junit/4.8.2/ total 248 **-rw-r--r-- 1 miquel miquel 237344 2012-09-13 11:01 junit-4.8.2.jar** -rw-r--r-- 1 miquel miquel    236 2012-09-13 11:13 junit-4.8.2-javadoc.jar.lastUpdated -rw-r--r-- 1 miquel miquel      0 2012-09-13 11:13 junit-4.8.2-javadoc.jar-not-available -rw-r--r-- 1 miquel miquel    458 2012-09-12 18:35 junit-4.8.2.pom -rw-r--r-- 1 miquel miquel    236 2012-09-13 11:13 junit-4.8.2-sources.jar.lastUpdated -rw-r--r-- 1 miquel miquel      0 2012-09-13 11:13 junit-4.8.2-sources.jar-not-available -rw-r--r-- 1 miquel miquel    163 2012-09-13 11:22 _maven.repositories miquel@ubuntu:~/creaveu/createOmegaMatrix$ 

The code is fine because in my laptop, which I have no access now, I van run:

mvn javadoc:javadoc mvn verify 

with no problems, and also the tests work in eclipse IDE.

like image 436
theme Avatar asked Sep 13 '12 09:09

theme


People also ask

What is JUnit package?

The org. junit package contains many interfaces and classes for junit testing such as Assert, Test, Before, After etc.

What is org JUnit Jupiter?

JUnit Jupiter is the combination of the programming model and extension model for writing tests and extensions in JUnit 5. The Jupiter sub-project provides a TestEngine for running Jupiter based tests on the platform. JUnit Vintage provides a TestEngine for running JUnit 3 and JUnit 4 based tests on the platform.

What is latest version of JUnit?

JUnit 5 is the latest generation of JUnit. It includes focussing on Java 8 and above with the facility of allowing various types of testing for developers on JVM. The latest release of the JUnit 5 generation is 5.7. 1 which was released in February 2021.


Video Answer


2 Answers

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>.

like image 165
Andrew Logvinov Avatar answered Oct 07 '22 00:10

Andrew Logvinov


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

like image 21
Siwei Avatar answered Oct 07 '22 01:10

Siwei