1

I need help troubleshooting a ClassNotFoundException in a Java project. The project is built using Maven. It contains a particular integration test that's run using the Failsafe plugin and TestNG. This test passes when I run it in my IDE (IntelliJ IDEA), but it fails with a ClassNotFoundException when I run it from the command line using mvn clean install.

Just to rule out environmental issues, I tried this on two computers, macOS and Ubunutu, and I get the same results on both of them. The Ubuntu computer only has one JVM installed, so IntelliJ and Maven must be using the same JVM on that machine. Both machines are using Java 1.8.

Unfortunately, I can't share the code because I don't own it. So, I'll try to describe the relevant details as much as I can. The integration test fails at runtime (not at compile time) on this line: Class c = MyPojo.class. The integration test and MyPojo are in different packages, but they're defined in the same Maven module, and therefore they're in the same jar file.

MyPojo is a simple POJO that:

  • is not declared to extend or implement anything.
  • has fields that only contain primitives and strings.
  • does not have any static initializers.
  • does not have a declared constructor.
  • has no imports.

I looked at the project's dependencies for another class named MyPojo with the same classpath, and I couldn't find any. Just to rule out a dependency conflict, I also tried renaming MyPojo to MyPojo2, and the result was that the ClassNotFoundException referenced MyPojo2.

mrog
  • 1,930
  • 3
  • 21
  • 28
  • Deleting the corresponding directories of projects that are involved in such a failing build from the local Maven repo (`~/.m2/repository`) sometimes helps to get rid off half-baked artifacts. – Gerold Broser Aug 09 '19 at 22:41

1 Answers1

1

Looks like this is a problem with the Failsafe plugin. I downgraded from 2.22.2 to 2.18.1 and now everything works.

mrog
  • 1,930
  • 3
  • 21
  • 28
  • 1
    Have you also seen [Maven Failsafe Classpath](https://stackoverflow.com/q/50787704/1744774): "_If run this test from my IDE (IntelliJ 2018.2 EAP) it passes fine, but running `mvn verify` fails_". – Gerold Broser Aug 09 '19 at 22:52
  • 1
    @GeroldBroser Thanks for pointing out that question. I confirmed that it's the same issue. I voted to close this question as a duplicate. – mrog Aug 12 '19 at 16:26