As part of our Consumer Driven Contract implementation, we are using PACT dependencies in our project to convert JSON to PACT file.
PACT dependencies added in Pom.xml file -
pact-jvm-consumer-junit_2.11 (version - 3.5.0)
pact-jvm-model (version - 3.5.0)
pact-jvm-pact-broker (version - 3.6.7)
These PACT dependencies are downloaded and bundled in jar using maven clean install command. And when we execute the jar on CloudOps VM and local server it works fine and gives the success response for the API. When the same jar is deployed successfully on PCF and we try to execute the API it returns NoClassDefFoundError for one of the PACT dependencies class - au.com.dius.pact.model.RequestResponsePact .
Below is the complete error from PCF logs -
2020, level: ERROR, thread: http-nio-8080-exec-8, loggerName: com.test.sample.common.aop.logging.LoggingAspect,
message: Exception in com.test.sample.cdcc.v1.process.CdccUploadProcessV1.cdcUploadedFiles() with cause = 'NULL' and exception = 'Could not initialize class au.com.dius.pact.model.RequestResponsePact',
error: java.lang.NoClassDefFoundError: Could not initialize class au.com.dius.pact.model.RequestResponsePact 2020-05-04T15:28:28.332+05:30 [APP/PROC/WEB/0] [OUT]
at au.com.dius.pact.consumer.dsl.PactDslResponse.toPact(PactDslResponse.java:265) 2020-05-04T15:28:28.332+05:30 [APP/PROC/WEB/0] [OUT]
at com.test.sample.cdcc.util.JsonToPactUtil.convertJSONtoPACT(JsonToPactUtil.java:47)
Below are few changes which we tried -
Switching these dependencies to lower version
Tried adding maven assembly plugin and creating a fat jar with all dependencies
Modifying scope of the dependencies to provided and compile
Adding class path in Maven jar plugin
But all these did not helped us to solve this issue. Could you point us in the right direction in solving this issue?
Below are the couple of ways i tried creating jar
Option1:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>${project.build.directory}/lib</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
Option2:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>