Ability to add additional jars are configured with these 2 parameters <configuration> <includePluginDependencies>true</includePluginDependencies> <!-- add in plugin dependencies --> <includeProjectDependencies>true</includeProjectDependencies> <!-- add in additional project dependencies -->
</configuration> full example located at java - Maven exec:exec - Need additional classpath elements for plugin - Stack Overflow<https://stackoverflow.com/questions/43239253/maven-execexec-need-additional-classpath-elements-for-plugin> [https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-i...@2.png?v=73d79a89bded]<https://stackoverflow.com/questions/43239253/maven-execexec-need-additional-classpath-elements-for-plugin> Maven exec:exec - Need additional classpath elements for plugin<https://stackoverflow.com/questions/43239253/maven-execexec-need-additional-classpath-elements-for-plugin> Turns out there are 2 options that you can use with Maven when using exec:java (which is what I wanted). You can specify true/false for each: stackoverflow.com Gruss martin~ ________________________________ From: Siddharth Jain <siddh...@gmail.com> Sent: Monday, July 25, 2022 11:22 AM To: Maven Users List <users@maven.apache.org> Subject: Re: java.lang.ClassNotFoundException: com.google.common.base.Preconditions I understand that. But we have been using maven exec:java for other projects and did not run into this exception with them. *So we want to understand why its not working here?* the debug log also shows that guava is added to the classpath. how can we debug this issue further? could this be a bug in maven? thanks. On Mon, Jul 25, 2022 at 3:49 AM Martin Gainty <mgai...@hotmail.com> wrote: > He advised you to not use exec:java which uses a configured classloader > He advised you use exec:exec > > Directions to use exec:exec provided here > Exec Maven Plugin – exec:exec (mojohaus.org)< > https://www.mojohaus.org/exec-maven-plugin/exec-mojo.html> > > Exec Maven Plugin - MojoHaus< > https://www.mojohaus.org/exec-maven-plugin/exec-mojo.html> > The executable. Can be a full path or the name of the executable. In the > latter case, the executable must be in the PATH for the execution to work. > www.mojohaus.org<http://www.mojohaus.org> > gruss > Martin > ________________________________ > From: Siddharth Jain <siddh...@gmail.com> > Sent: Sunday, July 24, 2022 8:13 PM > To: Maven Users List <users@maven.apache.org> > Subject: Re: java.lang.ClassNotFoundException: > com.google.common.base.Preconditions > > could you explain this to me? we have tried running without configuring any > agent > mvn exec:java -X -Dexec.mainClass=com.example.App > > and the exception is still there. and maven:exec works for other projects. > > On Sun, Jul 24, 2022 at 1:19 PM Bernd Eckenfels <e...@zusammenkunft.net> > wrote: > > > 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. > > >