Re: java.lang.ClassNotFoundException: com.google.common.base.Preconditions

2022-07-25 Thread Bernd Eckenfels
The problem is how your app (or the memory measuit lib) is loading classes. It 
does not seem to use the classloader from your application main class (which is 
the one maven provides prepared with your dependencies).

 Maybe it helps to set the thread context classloader with the app classloader 
(not sure if the maven plugin does that or not). But it might just not be 
possible to make your external code use this classloader, in that case starting 
a stand alone java might be easier.

Gruss
Bernd


--
http://bernd.eckenfels.net

Von: Siddharth Jain 
Gesendet: Monday, July 25, 2022 2:13:30 AM
An: Maven Users List 
Betreff: 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 
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 
> Gesendet: Sunday, July 24, 2022 8:46:04 PM
> An: 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. (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.
>


Re: java.lang.ClassNotFoundException: com.google.common.base.Preconditions

2022-07-25 Thread Martin Gainty

Ability to add additional jars are configured with these 2 parameters


true 


true 



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 
Sent: Monday, July 25, 2022 11:22 AM
To: Maven Users List 
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  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 
> Sent: Sunday, July 24, 2022 8:13 PM
> To: Maven Users List 
> 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 
> 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 
> > Gesendet: Sunday, July 24, 2022 8:46:04 PM
> > An: 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. (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-measure

Re: java.lang.ClassNotFoundException: com.google.common.base.Preconditions

2022-07-25 Thread Siddharth Jain
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  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
> gruss
> Martin
> 
> From: Siddharth Jain 
> Sent: Sunday, July 24, 2022 8:13 PM
> To: Maven Users List 
> 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 
> 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 
> > Gesendet: Sunday, July 24, 2022 8:46:04 PM
> > An: 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. (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
> >
> > /Li

Re: java.lang.ClassNotFoundException: com.google.common.base.Preconditions

2022-07-25 Thread Martin Gainty
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
gruss
Martin

From: Siddharth Jain 
Sent: Sunday, July 24, 2022 8:13 PM
To: Maven Users List 
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 
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 
> Gesendet: Sunday, July 24, 2022 8:46:04 PM
> An: 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. (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.
>


Re: java.lang.ClassNotFoundException: com.google.common.base.Preconditions

2022-07-24 Thread Siddharth Jain
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 
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 
> Gesendet: Sunday, July 24, 2022 8:46:04 PM
> An: 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. (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.
>


Re: java.lang.ClassNotFoundException: com.google.common.base.Preconditions

2022-07-24 Thread Bernd Eckenfels
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 
Gesendet: Sunday, July 24, 2022 8:46:04 PM
An: 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. (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.


Re: java.lang.ClassNotFoundException: com.google.common.base.Preconditions

2022-07-24 Thread Thomas Broyer
IIRC exec:java doesn't fork a new JVM so the java.class.path is the one
from Maven itself. Your dependencies are "only" in a custom classloader.
You might want to try exec:exec with java as the executable.

Le dim. 24 juil. 2022 à 20:46, Siddharth Jain  a écrit :

> 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. (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.
>


java.lang.ClassNotFoundException: com.google.common.base.Preconditions

2022-07-24 Thread Siddharth Jain
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. (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.