What container provider supports org.apache.cxf.jaxrs.JAXRSServerFactoryBean? - java

Using the information provided below can you answer the following questions:
What container provider supports org.apache.cxf.jaxrs.JAXRSServerFactoryBean so that I may add my application using org.glassfish.jersey.server.ContainerFactory when creating an end point?
What is wrong with the below application that causes (JAXRSServerFactoryBean)RuntimeDelegate.getInstance().createEndpoint(app, JAXRSServerFactoryBean.class); to throw an illegal argument exception?
I am attempting to deploy a JAX-RS application that uses annotations (no web.xml) to system that uses a Java Application Manager (it is a proprietary system that has ported over some application manager libraries but I am not sure what those are due to little supporting documentation around it).
At a high level I have a Java application that uses JAX-RS annotations, such as ApplicationPath, Path, Produces/Consumes, and JsonProperty, to attempt to create an endpoint on a "application server". I say "application server" because I have no documentation around this system so I am just going to call it that. When attempting to start the application I get the following exception:
java.lang.IllegalArgumentException: No container provider supports the type class org.apache.cxf.jaxrs.JAXRSServerFactoryBean
at org.glassfish.jersey.server.ContainerFactory.createContainer(ContainerFactory.java:64)
at org.glassfish.jersey.server.internal.RuntimeDelegateImpl.createEndpoint(RuntimeDelegateImpl.java:47)
at com.app.Server.startServer(Server.java:182)
I have researched the java.lang.IllegalArgumentException thrown by the org.glassfish.jersey.server.internal.RuntimeDelegateImpl.createEndpoint function. I am not sure why it would do this because on the cover it appears like the application class is annotated correctly and extends Application.
I was able to look at the Server's class code and here is what is being done:
Server Code
Here a snippet portion of com.app.Server.startServer(Server.java:182) code, I cannot alter this code:
inside of startServer...
Application app = (Application) Class.forName("com.app.MyApplication").newInstance();
JAXRSServerFactoryBean jaxrsServerFactory = (JAXRSServerFactoryBean)RuntimeDelegate.getInstance().createEndpoint(app, JAXRSServerFactoryBean.class);
Now my code:
Application Code
MyApplication
package com.app;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import com.app.services.ServiceOne;
#ApplicationPath("base/path")
public class MyApplication extends Application {
public MyApplication() {
System.out.println(Long.toString(System.nanoTime()) + " " + this.getClass().getName() + " constructor called...");
}
/* (non-Javadoc)
* #see javax.ws.rs.core.Application#getClasses()
*/
#Override
public Set<Class<?>> getClasses() {
System.out.println(Long.toString(System.nanoTime()) + " " + this.getClass().getName() + " getClasses() method called...");
Set<Class<?>> classes = new HashSet<>();
classes.add(ServiceOne.class);
return classes;
}
}
My Application's Services
package com.app.services.ServiceOne;
import java.util.ArrayList;
import javax.ws.rs.Consumes;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
// pretend the model imports are here...
#Path("serviceOne")
#Consumes(MediaType.APPLICATION_JSON)
#Produces(MediaType.APPLICATION_JSON)
public class ServiceOne {
#PUT
#Consumes(MediaType.APPLICATION_JSON)
#Produces(MediaType.APPLICATION_JSON)
public ResponseObject performService(InputObject body) throws NotFoundException {
// do whatever to get result and send...
}
}
Pom.xml Plugins and Dependencies
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.8</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-jdk-http</artifactId>
<version>2.28-RC4</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.28-RC4</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>2.28-RC4</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.28-RC4</version>
</dependency>
</dependencies>
Thanks again for your help!

I figured out the answer to my question.
The system I was attempting to deploy my application to already had jar files installed on the system in various directories.
I updated my application to include those jar files. This was done by updating a descriptor that I use to deploy the application to the system.
Then I and set the scope of certain dependencies in my pom.xml to <scope>provided</scope> so that when the application was packaged by maven, those dependencies would not be included in the final jar.
Below is an example:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-jdk-http</artifactId>
<version>2.28-RC4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.28-RC4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>2.28-RC4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.28-RC4</version>
<scope>provided</scope>
</dependency>
</dependencies>

This was fixed in my side by excluding jersey-server which has its own META-INF/services/javax.ws.rs.ext.RuntimeDelegate (see RuntimeDelegate.JAXRS_RUNTIME_DELEGATE_PROPERTY), hence preventing the proper loading of org.apache.cxf.jaxrs.impl.RuntimeDelegateImpl. In my case, jersey-server was brought transitively by hadoop-mapreduce-client-core:
<dependency>
<groupId>XXX</groupId>
<artifactId>YYY</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-core</artifactId>
</exclusion>
</exclusions>
</dependency>

Related

JUnit 5 throw method not found with Mockito.extension

I am updating a test from JUnit 4 to JUnit 5 (Jupiter).
Among the ordinary annotation adaptations such as #BeforeEach I am using #ExtendWith(MockitoExtension.class) to run the #mocks.
The code is like this:
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
#ExtendWith(MockitoExtension.class)
public class SomeTest {
private static final String TEST = "test";
#Mock
RetailerService retailerService;
private Delivery delivery;
#BeforeEach
public void setUp() {
when(retailerService.getMessage(any(String.class))).thenReturn(TEST);
delivery = new Delivery(retailerService);
}
#Test
public void should_have_delivery() {
assertEquals(getExpectedDeliveriesDTOs(), delivery.toDtos());
}
}
However when I run the test I am getting the following error:
java.lang.NoSuchMethodError: org.mockito.session.MockitoSessionBuilder.initMocks([Ljava/lang/Object;)Lorg/mockito/session/MockitoSessionBuilder;
I saw on this comment: https://stackoverflow.com/a/49655834/2182500 , that this error can be a consequence of having different versions of junit-jupiter-api as dependency in the projects POM and the one in the run scope used by mockito-junit-jupiter.
So I guaranteed to import the same version dependency for Jupiter, but I am still seeing the same error.
pom entries. at surefire level:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Dfile.encoding=${project.build.sourceEncoding}</argLine>
<skipTests>true</skipTests>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.1.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
at JUnit level:
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>2.17.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.1.0</version>
<scope>test</scope>
</dependency>
Has anyone bumped into this before and can help?
Thank you in advance.
Turns out this error was related to the Mockito dependencies versions. Thus, failling to initalize mocks.
The project I was working at had an old version of mockito-core artifact that did not have a related mockito-junit-jupiter version. the project needs to maintain mockito-coredue to Junit4 tests mock annotaions. Problem was solved by updating version of mockito core and using same version for mockito-junit-jupiter. Like this:
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>

Cucumber test ignored - TestNG

I hope my second question on SO is well scripted. I am trying to automate test cases using Gherkin, TestNG and Selenium in Java. Using a Maven project with Intellij.
I am able to launch my Test Case when I launch them in the .feature file but when I use the testng.xml file or the Test Runner class, it somehow ignores the Test Case.
I have already checked the project settings which seems to be properly configured. Also checked that I have proper dependencies in my pom.xml (I hope I do)
My test.feature
Feature: Xray Jira
#TEST_01 #STC
Scenario: Xray Jira Testing
Given The user login to the application
When the credentials are entered
Then the homepage is viewed
My test Runner
package Runners;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
import org.testng.annotations.DataProvider;
#CucumberOptions(
features = "src/test/resources/",
glue = {"src/test/Steps/"},
plugin = {
"pretty",
"html:target/cucumber-reports/cucumber-pretty",
"json:target/cucumber-reports/CucumberTestReport.json"
})
public class UITest extends AbstractTestNGCucumberTests {
}
My step definition - the following code in the step definitions are
working when I launch the test case from the feature file
package Steps;
import Pages.BasePage;
import Pages.HomePage;
import Pages.LoginPage;
import Helper.ConfigFileReader;
import io.cucumber.java.en.*;
import org.openqa.selenium.WebDriver;
import org.testng.Assert;
public class MyStepdefs extends BasePage {
private WebDriver driver = null;
private Hooks lHooks;
public MyStepdefs(Hooks lHooks) {
this.driver = lHooks.driver;
}
#Given("The user login to the application")
public void the_user_login_to_the_application() {
LoginPage loginObject = new LoginPage(driver);
resultValue = loginObject.VerifyUrl();
Assert.assertTrue(resultValue);
}
#When("the credentials are entered")
public void the_credentials_are_entered() {
ConfigFileReader config = new ConfigFileReader();
String userID = config.getUserID();
String userPassword = config.getUserPassword();
LoginPage loginObject = new LoginPage(driver);
loginObject.enterName(userID);
loginObject.enterPassword(userPassword);
loginObject.clickLoginButton();
HomePage lHome = new HomePage(driver);
resultValue=lHome.verifyMenuIsDisplayed();
Assert.assertTrue(resultValue);
}
#Then("the homepage is viewed")
public void the_homepage_is_viewed() {
HomePage homeObject = new HomePage(driver);
resultValue=homeObject.verifyMenuIsDisplayed();
Assert.assertTrue(resultValue);
}
My POM.xml
//Below is my POM.xml I usually followed different tutorials online to get the dependencies. I had issues with compatibility of different version of the dependencies. I was able to correct them. Not sure if it is still the problem
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>execute_auto</groupId>
<artifactId>execute_auto</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-core -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
<version>4.7.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>4.7.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/gherkin -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>gherkin</artifactId>
<version>5.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-jvm-deps -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.6</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>4.7.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.0.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-picocontainer -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>4.7.1</version>
</dependency>
<!-- Web driver manager dependency -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>3.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>3.6.2</version>
<scope>compile</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<suiteXmlFiles>testng.xml</suiteXmlFiles>
</configuration>
</plugin>
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>3.15.0</version>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>POC-language-testing</projectName>
<outputDirectory>target/cucumber-reports/advanced-reports</outputDirectory>
<cucumberOutput>target/cucumber-reports/CucumberTestReport.json</cucumberOutput>
<buildNumber>1</buildNumber>
<parallelTesting>false</parallelTesting>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
My expected result should be that the test is passed. But it is always ignored when launched via testng.xml or the runner class. I would be more than glad if anyone could he be of help
PS: My final objective is to automate and launch test cases on Intellij with Cucumber and Java using Page Object Model. This should update the test cases on Xray in Jira. If anyone has any useful link with respect to such functionalities, it would be much appreciated.
The glue element should be a package name, not a directory. So if your steps are in the package Steps then the glue should be Steps.
Additionally TestNG swallows the message in the SkipException exceptions thrown by Cucumber so you should add the summary plugin to see why Cucumber skipped the test (most likely due to an undefined step because you didn't have the glue configured properly).
#CucumberOptions(
features = "src/test/resources/",
glue = {"Steps"},
plugin = {
"summary"
"pretty",
"html:target/cucumber-reports/cucumber-pretty",
"json:target/cucumber-reports/CucumberTestReport.json"
})
public class UITest extends AbstractTestNGCucumberTests {
}
As an aside: You should not include transitive dependencies in your pom. You can and should remove the cucumber-core, gherkin and cucumber-jvm-deps dependencies.

ClassNotFoundException: io.opencensus.trace.propagation.TextFormat not found

I have a module in apache karaf 4.2.6 with java 11 that validates purchase receipts in Google Play. I'm using androidpublisher.
When it sends a request for the first time I get an error in OpenCensusUtils class:
androidPublisher.purchases().products().get(packageName, productId, purchaseToken).execute()
java.lang.ClassNotFoundException: io.opencensus.trace.propagation.TextFormat not found by wrap_file__Users_USER_NAME_.m2_repository_io_opencensus_opencensus-contrib-http-util_0.22.1_opencensus-contrib-http-util-0.22.1.jar
In subsequent times I get error in com.google.api.client.http.HttpRequest class at this point private final Tracer tracer = OpenCensusUtils.getTracer():
java.lang.NoClassDefFoundError: Could not initialize class com.google.api.client.http.OpenCensusUtils
Here is dependencies:
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-androidpublisher</artifactId>
<version>v3-rev92-1.25.0</version>
<exclusions>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client</artifactId>
<version>1.29.2</version>
</dependency>
<dependency>
<groupId>io.opencensus</groupId>
<artifactId>opencensus-api</artifactId>
<version>0.22.1</version>
</dependency>
<dependency>
<groupId>io.opencensus</groupId>
<artifactId>opencensus-contrib-http-util</artifactId>
<version>0.22.1</version>
</dependency>
Also google-api-client, google-http-client-jackson2 and google-oauth-client has version 1.29.2
In karaf I see the library opencensus-api is exporting a package io.opencensus.trace.propagation that contains a class TextFormat.
What am I doing wrong?
I resolved by adding io.opencensus and io.grpc to the Private-Package of the module's build area as follows. It made them embed locally.
....
<build>
<plugins>
<plugin>
....
<configuration>
<instructions>
<Bundle-SymbolicName> ${project.artifactId} </Bundle-SymbolicName>
<Private-Package>
META-INF.services;-split-package:=merge-first,
com.google.*;-split-package:=merge-first,
io.opencensus.*;-split-package:=merge-first,
io.grpc.*;-split-package:=merge-first
</Private-Package>
....

The import javax.servlet cannot be resolved (only in runtime) [duplicate]

I was trying to implement a login filter in my web app with jsf 2, following this guide:
https://stackoverflow.com/tags/servlet-filters/info
after I compiled my filter and added the .class in "web-inf/classes" (as the guide says) the filter worked, but i put the wrong url to redirect to the login page so i deleted the filter.class from the folder (web-inf/classes) and tried to compile the project again , but it failed, and since then im getting "package javax.servlet does not exist"
it is weird because before it was working and i have javax.servlet in my pom.xml.. i tried cleaning the project, but nothing.
this is my filter class:
package Bean;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
* Created with IntelliJ IDEA.
* User: rodrigo
* Date: 28-04-13
* Time: 06:54 AM
* To change this template use File | Settings | File Templates.
*/
#WebFilter("/Contenido/*")
public class filtro implements Filter {
#Override
public void init(FilterConfig config) throws ServletException {
// If you have any <init-param> in web.xml, then you could get them
// here by config.getInitParameter("name") and assign it as field.
}
#Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws ServletException, IOException {
HttpServletRequest req = (HttpServletRequest) request;
LoginBean user = (LoginBean) req.getSession().getAttribute("user");
if (user != null && user.isLoggedIn()) {
// User is logged in, so just continue request.
chain.doFilter(request, response);
} else {
// User is not logged in, so redirect to index.
HttpServletResponse res = (HttpServletResponse) response;
res.sendRedirect(req.getContextPath() + "/Contenido/Login.xhtml");
}
}
#Override
public void destroy() {
// If you have assigned any expensive resources as field of
// this Filter class, then you could clean/close them here.
}
}
this is the error:
\Users\rodrigo\IdeaProjects\Frutemu\src\main\java\Bean\filtro.java:[5,20] error: package javax.servlet does not exist
[ERROR] \Users\rodrigo\IdeaProjects\Frutemu\src\main\java\Bean\filtro.java:[6,20] error: package javax.servlet does not exist
[ERROR] \Users\rodrigo\IdeaProjects\Frutemu\src\main\java\Bean\filtro.java:[7,20] error: package javax.servlet does not exist
[ERROR] \Users\rodrigo\IdeaProjects\Frutemu\src\main\java\Bean\filtro.java:[8,20] error: package javax.servlet does not exist
[ERROR] \Users\rodrigo\IdeaProjects\Frutemu\src\main\java\Bean\filtro.java:[9,20] error: package javax.servlet does not exist
[ERROR] \Users\rodrigo\IdeaProjects\Frutemu\src\main\java\Bean\filtro.java:[10,20] error: package javax.servlet does not exist
[ERROR] \Users\rodrigo\IdeaProjects\Frutemu\src\main\java\Bean\filtro.java:[11,31] error: package javax.servlet.annotation does not exist
my pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Frutemu</groupId>
<artifactId>Frutemu</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>Frutemu Maven Webapp</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>prime-repo</id>
<name>Prime Repo</name>
<url>http://repository.primefaces.org</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb-api</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>all-themes</artifactId>
<version>1.0.9</version>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.0.2-b10</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- MySQL database driver -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.21</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>el-impl</artifactId>
<version>2.2.1-b04</version>
<scope>provided</scope>
</dependency>
<!-- OpenJPA framework -->
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-all</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>4.1.2</version>
</dependency>
</dependencies>
<build>
<finalName>Frutemu</finalName>
<plugins>
<!-- Open Jpa -->
<plugin>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-maven-plugin</artifactId>
<version>2.2.0</version>
<configuration>
<includes>**/model/*.class</includes>
<addDefaultConstructor>true</addDefaultConstructor>
<enforcePropertyRestrictions>true</enforcePropertyRestrictions>
</configuration>
<executions>
<execution>
<id>enhancer</id>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Plugin para levantar una instancia de Tomcat 7 liviana, única para este proyecto -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<url>http://127.0.0.1:8080/manager/text</url>
<server>TomcatServer</server>
<path>/Frutemu</path>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jasperreports-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compile-reports</goal>
</goals>
</execution>
</executions>
<dependencies>
<!--note this must be repeated here to pick up correct xml validation -->
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>4.1.2</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
The javax.servlet dependency is missing in your pom.xml. Add the following to the dependencies-Node:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
I only put this code in my pom.xml and I executed the command maven install.
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
The answer provided by #Matthias Herlitzius is mostly correct. Just for further clarity.
The servlet-api jar is best left up to the server to manage see here for detail
With that said, the dependency to add may vary according to your server/container. For example in Wildfly the dependency would be
<dependency>
<groupId>org.jboss.spec.javax.servlet</groupId>
<artifactId>jboss-servlet-api_3.1_spec</artifactId>
<scope>provided</scope>
</dependency>
So becareful to check how your container has provided the servlet implementation.
I needed to import javaee-api as well.
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>
Unless I got following error:
package javax.servlet.http does not exist
javax.servlet.annotation does not exist
javax.servlet.http does not exist
...
In my case, migrating a Spring 3.1 app up to 3.2.7, my solution was similar to Matthias's but a bit different -- thus why I'm documenting it here:
In my POM I found this dependency and changed it from 6.0 to 7.0:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
Then later in the POM I upgraded this plugin from 6.0 to 7.0:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
...
<configuration>
...
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
I got here with a similar problem with my Gradle build and fixed it in a similar way:
Unable to load class hudson.model.User due to missing dependency javax/servlet/ServletException
fixed with:
dependencies {
implementation('javax.servlet:javax.servlet-api:3.0.1')
}
I ran into the same error when using IntelliJ IDEA despite having javax.servlet-api listed as a dependency in my pom.xml file.
Turns out my Java project did not have Maven framework support. Here is how I added it:
Right click on the project in Project View -> select 'Add Framework Support...'
Select 'Maven'
In the Maven View that shows up, click 'Download Sources and/or Documentation'
Hope this helps anyone new to IntelliJ IDEA.
maybe doesnt exists javaee-api-7.0.jar.
download this jar and on your project right clik
on your project right click
build path
Configure build path
Add external Jars
javaee-api-7.0.jar choose
Apply and finish

NoSuchMethod error when running Spring MVC test

I'm trying to follow the examples in Spring in Action (4th edition), chapter 5 to create my own project. (Still a newbie at enterprise-level stuff) I'm using a Windows 7 PC, Java 7, Spring 4 and Maven. When I run my ClinicalNoteControllerTest, the test fails with a NoSuchMethod error on a specific line. But I've researched this line, and it seems to be written correctly. It definitely follows the example in the book. I've debugged, but can't find anything in what turns up there. I'm wondering if I don't have the correct configuration in my pom.xml file?
You guys are always so helpful, and I'll appreciate any help you can give finding a solution here. But I also want to become a better troubleshooter myself and not just run to stackoverflow every time I hit a bump. So any tips you can give on how I could troubleshoot this problem myself will be greatly appreciated.
Here is the test:
package com.kwalker.practicewellness;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.junit.Test;
import static org.mockito.Mockito.*;
import org.springframework.test.web.servlet.MockMvc;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*;
import static org.hamcrest.Matchers.*;
import org.springframework.web.servlet.view.InternalResourceView;
import com.kwalker.practicewellness.data.ClinicalNoteRepository;
import com.kwalker.practicewellness.domain.ClinicalNote;
import com.kwalker.practicewellness.web.ClinicalNoteController;
public class ClinicalNoteControllerTest {
#Test
public void shouldShowRecentClinicalNotes() throws Exception {
List<ClinicalNote> expectedClinicalNotes = createClinicalNoteList(20);
ClinicalNoteRepository mockNoteRepository = mock(ClinicalNoteRepository.class);
when(mockNoteRepository.findClinicalNotes(Long.MAX_VALUE, 20)).thenReturn(expectedClinicalNotes);
ClinicalNoteController noteController = new ClinicalNoteController(mockNoteRepository);
MockMvc mockMvc = standaloneSetup(noteController).setSingleView(
new InternalResourceView("/WEB-INF/views/clinicalNotes.jsp")).build();
mockMvc.perform(get("/clinical-notes"))
.andExpect(view().name("clinicalNotes"))
.andExpect(model().attributeExists("clinicalNoteList"))
.andExpect(model().attribute("clinicalNoteList", hasItems(expectedClinicalNotes.toArray())));
}
private List<ClinicalNote> createClinicalNoteList(int count) {
List<ClinicalNote> clinicalNotes = new ArrayList<ClinicalNote>();
for (int i=0; i < count; i++) {
clinicalNotes.add(new ClinicalNote("Note " + i, new Date()));
}
return clinicalNotes;
}
}
Here is the ClinicalNoteController:
package com.kwalker.practicewellness.web;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.kwalker.practicewellness.data.ClinicalNoteRepository;
#Controller
#RequestMapping("/clinical-notes")
public class ClinicalNoteController {
private ClinicalNoteRepository noteRepository;
#Autowired
public ClinicalNoteController(ClinicalNoteRepository noteRepository) {
this.noteRepository = noteRepository;
}
#RequestMapping(method=RequestMethod.GET)
public String clinicalNotes(Model model) {
model.addAttribute("clinicalNoteList", noteRepository.findClinicalNotes(Long.MAX_VALUE, 20));
return "clinicalNotes";
}
}
Here is what prints out on the console when I run the test:
INFO : org.springframework.test.web.servlet.setup.StandaloneMockMvcBuilder$StaticRequestMappingHandlerMapping - Mapped "{[/clinical-notes],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.kwalker.practicewellness.web.ClinicalNoteController.clinicalNotes(org.springframework.ui.Model)
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter - Looking for #ControllerAdvice: org.springframework.test.web.servlet.setup.StubWebApplicationContext#41494678
INFO : org.springframework.mock.web.MockServletContext - Initializing Spring FrameworkServlet ''
INFO : org.springframework.test.web.servlet.TestDispatcherServlet - FrameworkServlet '': initialization started
INFO : org.springframework.test.web.servlet.TestDispatcherServlet - FrameworkServlet '': initialization completed in 16 ms
Here is the failure trace:
java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Description;)V
at org.hamcrest.core.IsCollectionContaining.matchesSafely(IsCollectionContaining.java:31)
at org.hamcrest.core.IsCollectionContaining.matchesSafely(IsCollectionContaining.java:14)
at org.hamcrest.TypeSafeDiagnosingMatcher.matches(TypeSafeDiagnosingMatcher.java:55)
at org.hamcrest.core.AllOf.matches(AllOf.java:24)
at org.springframework.test.util.MatcherAssertionErrors.assertThat(MatcherAssertionErrors.java:65)
at org.springframework.test.web.servlet.result.ModelResultMatchers$1.match(ModelResultMatchers.java:56)
at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:152)
at com.kwalker.practicewellness.ClinicalNoteControllerTest.shouldShowRecentClinicalNotes(ClinicalNoteControllerTest.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Here is my POM file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.kwalker</groupId>
<artifactId>practicewellness</artifactId>
<name>Practice Wellness</name>
<packaging>war</packaging>
<version>1.0.0-BUILD-SNAPSHOT</version>
<properties>
<java-version>1.7</java-version>
<org.springframework-version>4.1.4.RELEASE</org.springframework-version>
<org.aspectj-version>1.6.10</org.aspectj-version>
<org.slf4j-version>1.6.6</org.slf4j-version>
</properties>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- AspectJ -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${org.aspectj-version}</version>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
<scope>runtime</scope>
</dependency>
<!-- #Inject -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
</dependency>
<!-- Misc -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<additionalProjectnatures>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
</additionalProjectnatures>
<additionalBuildcommands>
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
</additionalBuildcommands>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.1</version>
<configuration>
<mainClass>org.test.int1.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
Here is my webapp initializer:
package com.kwalker.practicewellness.config;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
public class WellnessWebAppInitializer extends
AbstractAnnotationConfigDispatcherServletInitializer {
#Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[] { RootConfig.class };
}
#Override
protected Class<?>[] getServletConfigClasses() {
return new Class<?>[] { WebConfig.class };
}
#Override
protected String[] getServletMappings() {
return new String[] { "/" };
}
}
Here is my WebConfig file:
package com.kwalker.practicewellness.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
#Configuration
#EnableWebMvc
#ComponentScan("com.kwalker.practicewellness.web")
public class WebConfig extends WebMvcConfigurerAdapter {
#Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
resolver.setExposeContextBeansAsAttributes(true);
return resolver;
}
#Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
}
Here is the RootConfig class:
package com.kwalker.practicewellness.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
#Configuration
#ComponentScan(basePackages={"com.kwalker.practicewellness"},
excludeFilters={#Filter(type=FilterType.ANNOTATION, value=EnableWebMvc.class)})
public class RootConfig {
}
This exact problem is addressed on Ted Vinke's blog from December 2013: Mixing JUnit, Hamcrest and Mockito
I used the code given on this page to modify my POM file (which basically involved rearranging mockito, junit and hamcrest, and excluding hamcrest on the mockito dependency). IMPORTANT TO NOTE: I was using the latest versions of these resources, and the fix DID NOT WORK until I made the versions in my POM file match the versions shown on the page at that link. Here is the text from the link:
This could be due to the fact that JUnit itself brings along its own version of Hamcrest as a transitive dependency. Now if you would be using JUnit 4.11 it would depending on Hamcrest 1.3 already.... Getting above error would be weird – since the describeMismatch method is present in org.hamcrest.Matcher interface. There seems to be an older version of org.hamcrest.Matcher present on the classpath to which org.junit.Assert.assertThat delegates. If you run this from Eclipse or IntelliJ, there’s a high chance that the IDE uses its own version of JUnit instead of your Maven dependency....
The article continues:
If we we’re looking in Eclipse for the Matcher classes we e.g. could see that there’s also one in mockito-all-1.9.5.jar.... Seems mockito-all is incompatible with JUnit 4.11 for backwards-compatibility reasons. The Hamcrest version 1.1 Matcher has been packaged within the dependency, so we can not exclude it.... Luckily for us, Mockito allows to us to use a mockito-core dependency instead of mockito-all. Running a dependency check (with dependency:tree or online) shows us it depends on hamcrest-core..... We can exclude it in the pom.xml and – no more NoSuchMethodError. Here’s the final combination of dependencies in our case:
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.9.5</version>
<exclusions>
<exclusion>
<artifactId>hamcrest-core</artifactId>
<groupId>org.hamcrest</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<exclusions>
<exclusion>
<artifactId>hamcrest-core</artifactId>
<groupId>org.hamcrest</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
</dependency>
I just had a similar issue and I was trying to track where junit, mockito and hamcrest was been import as dependency to understand what have changed (we have not changed the code in any way).
We found a "RELEASE" value as version to a pom dependency (spring-test from org.springframework). So looks like a new version of this dependency is no compatible with the others libs. After removing the version tag the problem was solved. After that we even removed the depedency since it was already contained on other dependencies.

Categories