Since exec:java executes in the running JVM it does not reconfigure the (boot)classpath but provides a configured classloader. It looks like the measuring agent does not like that. In that Case you need either exec:exec or a plug-in for that purpose.
Gruss Bernd -- http://bernd.eckenfels.net ________________________________ Von: Siddharth Jain <siddh...@gmail.com> Gesendet: Sunday, July 24, 2022 8:46:04 PM An: users@maven.apache.org <users@maven.apache.org> Betreff: java.lang.ClassNotFoundException: com.google.common.base.Preconditions we are running into the dreaded ClassNotFoundException in a project. Here is the setup. Using JDK 11 and Maven 3.8.5. Trying to create sample test project that uses memory-measurer <https://github.com/DimitrisAndreou/memory-measurer> to measure memory. First we mvn packaged and installed the memory-measurer artifact into M2 repository. Then we created a test project in which we add dependency on memory-measurer. The project compiles fine but gives error on running (we run using mvn exec:java plugin): Caused by: java.lang.ClassNotFoundException: com.google.common.base.Preconditions at jdk.internal.loader.BuiltinClassLoader.loadClass (BuiltinClassLoader.java:581) at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass (ClassLoaders.java:178) at java.lang.ClassLoader.loadClass (ClassLoader.java:521) at objectexplorer.InstrumentationGrabber.checkSetup (InstrumentationGrabber.java:20) at objectexplorer.InstrumentationGrabber.instrumentation (InstrumentationGrabber.java:25) at objectexplorer.MemoryMeasurer.<clinit> (MemoryMeasurer.java:24) at com.example.App.main (App.java:20) at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:254) at java.lang.Thread.run (Thread.java:834) What have we tried? Here is output of mvn dependency:build-classpath: /Users/xxx/.m2/repository/objectexplorer/memory-measurer/1.0-SNAPSHOT/memory-measurer-1.0-SNAPSHOT.jar:/Users/xxx/.m2/repository/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar:/Users/xxx/.m2/repository/com/google/guava/guava/19.0/guava-19.0.jar:/Users/xxx/.m2/repository/junit/junit/4.11/junit-4.11.jar:/Users/xxx/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar we unpacked guava-19.0.jar in a temp directory and can see -rw-r--r-- 1 xxx staff 5252 Aug 25 2014 /Users/xxx/temp/com/google/common/base/Preconditions.class in it. The next thing we tried is printing System.getProperty("java.class.path"). This gives: /Library/Downloads/apache-maven-3.8.5/boot/plexus-classworlds-2.6.0.jar above does not contain the classpath calculated by mvn dependency plugin. Question 1: Why? Question 2: When we printed System.getProperty("java.class.path") in another working project we got same result. It seems the classpath when using mvn exec:java is always /Library/Downloads/apache-maven-3.8.5/boot/plexus-classworlds-2.6.0.jar How is the other project able to load classes from above classpath? Why is mvn exec:java not using correct classpath? How do we fix this? Here <https://gist.github.com/siddjain/5d2afee15a756b689c5231488e6c29be> is output of maven with the -X switch. You can see following debug info: [DEBUG] Adding project dependency artifact: memory-measurer to classpath [DEBUG] Adding project dependency artifact: jsr305 to classpath *[DEBUG] Adding project dependency artifact: guava to classpath* here <https://gist.github.com/siddjain/2ceaca405acdaf460df94a064e07c17f> is pom.xml. would be great if someone could help us out.