You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Neil Chaudhuri <nc...@potomacfusion.com> on 2011/01/14 20:27:14 UTC

Classloader Problem with Maven 3.0.2

I have upgraded from Maven 2.20 to 3.02, and I found many of my integration tests that used to pass are now failing because of a ClassCastException, which is an odd exception to find when no code has changed. I traced the issue to a classloader problem with Maven 3 that arises in another Java library (RESTEasy if you were wondering).

Here is their code:

try
      {
         Object delegate =
                 FactoryFinder.find(JAXRS_RUNTIME_DELEGATE_PROPERTY,
                         JAXRS_DEFAULT_RUNTIME_DELEGATE);
         if (!(delegate instanceof RuntimeDelegate))
         {
            Class pClass = RuntimeDelegate.class;
            String classnameAsResource = pClass.getName().replace('.', '/') + ".class";
            ClassLoader loader = pClass.getClassLoader();
            if (loader == null)
            {
               loader = ClassLoader.getSystemClassLoader();
            }
            URL targetTypeURL = loader.getResource(classnameAsResource);
           throw new LinkageError("ClassCastException: attempting to cast" +
                    delegate.getClass().getClassLoader().getResource(classnameAsResource) +
                    "to" + targetTypeURL.toString());
         }
         return (RuntimeDelegate) delegate;
      }
      catch (Exception ex)
      {
         throw new RuntimeException(ex);
      }

And here is my pom configuration:

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>failsafe-maven-plugin</artifactId>
                <version>2.4.3-alpha-1</version>
                <configuration>
                    <useSystemClassLoader>false</useSystemClassLoader>
                    <useManifestOnlyJar>false</useManifestOnlyJar>
                    <forkMode>once</forkMode>
                    <includes>
                        <include>**/CategoriesServiceDelegateIT.java</include>
                    </includes>
                </configuration>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>verify</id>
                        <goals>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
</plugin>

When I set useSystemClassLoader to true, the ClassCastException goes away, but then nothing happens except for a hard exit. I see nothing in the logs or in failsafe-reports to tell me what happened.

Any insight into why things work in Maven 2.20 but not in 3.02 is appreciated.

Thanks.

Re: Classloader Problem with Maven 3.0.2

Posted by Wayne Fay <wa...@gmail.com>.
> Any insight into why things work in Maven 2.20 but not in 3.02 is appreciated.

I don't believe that Maven 2.20 is a real version. Of course, 3.02
doesn't exist either, but I assume that is supposed to be 3.0.2. So
are you trying to upgrade from 2.2.0? Have you tried with 2.2.1?

Are you using the exact same <plugin/> configuration (with the plugin
versions declared etc) and only changing the Maven version? Have you
tried mvn -X to get more information about what is going on during
your build, and compared the output from mvn2 and mvn3?

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Classloader Problem with Maven 3.0.2

Posted by Wayne Fay <wa...@gmail.com>.
> A closer look at the logs show that Surefire runs the unit tests, then Failsafe runs
> the single unit test configured (which fails because of the classloader issues I
> began the thread with), and then Failsafe runs all the integration tests.
>
> Clearly something is misconfigured to cause that third block of testing and to
> create the classloader errors. Any insight is appreciated.

Did you check "mvn help:effective-pom" in your project/module to be
certain that some plugin configuration from a parent pom etc is not
contributing a configuration you had forgotten about or simply did not
realize was in effect to cause this third execution?

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


RE: Classloader Problem with Maven 3.0.2

Posted by Neil Chaudhuri <nc...@potomacfusion.com>.
A closer look at the logs show that Surefire runs the unit tests, then Failsafe runs the single unit test configured (which fails because of the classloader issues I began the thread with), and then Failsafe runs all the integration tests.

Clearly something is misconfigured to cause that third block of testing and to create the classloader errors. Any insight is appreciated.

Thanks. 


-----Original Message-----
From: Neil Chaudhuri 
Sent: Friday, January 14, 2011 6:46 PM
To: Maven Users List
Subject: RE: Classloader Problem with Maven 3.0.2

I upgraded Failsafe to 2.7.1, and things definitely progressed, but two interesting things are happening:

1) Every test runs even though I configure for only one test to run as you will see below.
2) All my tests that extend AbstractTestNGSpringContextTests are having problems with loading the application context. Sounds like some classloader stuff going on with Maven interacting with Spring and RESTEasy.

Again, everything works perfectly with Maven 2.2.0.

Here is the configuration again:


            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.7.1</version>
                <configuration>
                    <useSystemClassLoader>true</useSystemClassLoader>
                    <useManifestOnlyJar>false</useManifestOnlyJar>
                    <includes>
                        <include>**/CategoriesServiceDelegateIT.java</include>
                    </includes>
                </configuration>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>verify</id>
                        <goals>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>




Thanks.




-----Original Message-----
From: anders.g.hammar@gmail.com [mailto:anders.g.hammar@gmail.com] On Behalf Of Anders Hammar
Sent: Friday, January 14, 2011 4:30 PM
To: Maven Users List
Subject: Re: Classloader Problem with Maven 3.0.2

You're using an old and deprecated version of the failsafe plugin. I don't
think it works with Maven 3.
failsafe-m-p is now found at Apache Maven (not Codehaus Mojo):
http://maven.apache.org/plugins/maven-failsafe-plugin/

Upgrade and retry!

/Anders

On Fri, Jan 14, 2011 at 20:27, Neil Chaudhuri
<nc...@potomacfusion.com>wrote:

> I have upgraded from Maven 2.20 to 3.02, and I found many of my integration
> tests that used to pass are now failing because of a ClassCastException,
> which is an odd exception to find when no code has changed. I traced the
> issue to a classloader problem with Maven 3 that arises in another Java
> library (RESTEasy if you were wondering).
>
> Here is their code:
>
> try
>      {
>         Object delegate =
>                 FactoryFinder.find(JAXRS_RUNTIME_DELEGATE_PROPERTY,
>                         JAXRS_DEFAULT_RUNTIME_DELEGATE);
>         if (!(delegate instanceof RuntimeDelegate))
>         {
>            Class pClass = RuntimeDelegate.class;
>            String classnameAsResource = pClass.getName().replace('.', '/')
> + ".class";
>            ClassLoader loader = pClass.getClassLoader();
>            if (loader == null)
>            {
>               loader = ClassLoader.getSystemClassLoader();
>            }
>            URL targetTypeURL = loader.getResource(classnameAsResource);
>           throw new LinkageError("ClassCastException: attempting to cast" +
>
>  delegate.getClass().getClassLoader().getResource(classnameAsResource) +
>                    "to" + targetTypeURL.toString());
>         }
>         return (RuntimeDelegate) delegate;
>      }
>      catch (Exception ex)
>      {
>         throw new RuntimeException(ex);
>      }
>
> And here is my pom configuration:
>
> <plugin>
>                <groupId>org.codehaus.mojo</groupId>
>                <artifactId>failsafe-maven-plugin</artifactId>
>                <version>2.4.3-alpha-1</version>
>                <configuration>
>                    <useSystemClassLoader>false</useSystemClassLoader>
>                    <useManifestOnlyJar>false</useManifestOnlyJar>
>                    <forkMode>once</forkMode>
>                    <includes>
>
>  <include>**/CategoriesServiceDelegateIT.java</include>
>                    </includes>
>                </configuration>
>                <executions>
>                    <execution>
>                        <id>integration-test</id>
>                        <goals>
>                            <goal>integration-test</goal>
>                        </goals>
>                    </execution>
>                    <execution>
>                        <id>verify</id>
>                        <goals>
>                            <goal>verify</goal>
>                        </goals>
>                    </execution>
>                </executions>
> </plugin>
>
> When I set useSystemClassLoader to true, the ClassCastException goes away,
> but then nothing happens except for a hard exit. I see nothing in the logs
> or in failsafe-reports to tell me what happened.
>
> Any insight into why things work in Maven 2.20 but not in 3.02 is
> appreciated.
>
> Thanks.
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


RE: Classloader Problem with Maven 3.0.2

Posted by Neil Chaudhuri <nc...@potomacfusion.com>.
I upgraded Failsafe to 2.7.1, and things definitely progressed, but two interesting things are happening:

1) Every test runs even though I configure for only one test to run as you will see below.
2) All my tests that extend AbstractTestNGSpringContextTests are having problems with loading the application context. Sounds like some classloader stuff going on with Maven interacting with Spring and RESTEasy.

Again, everything works perfectly with Maven 2.2.0.

Here is the configuration again:


            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.7.1</version>
                <configuration>
                    <useSystemClassLoader>true</useSystemClassLoader>
                    <useManifestOnlyJar>false</useManifestOnlyJar>
                    <includes>
                        <include>**/CategoriesServiceDelegateIT.java</include>
                    </includes>
                </configuration>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>verify</id>
                        <goals>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>




Thanks.




-----Original Message-----
From: anders.g.hammar@gmail.com [mailto:anders.g.hammar@gmail.com] On Behalf Of Anders Hammar
Sent: Friday, January 14, 2011 4:30 PM
To: Maven Users List
Subject: Re: Classloader Problem with Maven 3.0.2

You're using an old and deprecated version of the failsafe plugin. I don't
think it works with Maven 3.
failsafe-m-p is now found at Apache Maven (not Codehaus Mojo):
http://maven.apache.org/plugins/maven-failsafe-plugin/

Upgrade and retry!

/Anders

On Fri, Jan 14, 2011 at 20:27, Neil Chaudhuri
<nc...@potomacfusion.com>wrote:

> I have upgraded from Maven 2.20 to 3.02, and I found many of my integration
> tests that used to pass are now failing because of a ClassCastException,
> which is an odd exception to find when no code has changed. I traced the
> issue to a classloader problem with Maven 3 that arises in another Java
> library (RESTEasy if you were wondering).
>
> Here is their code:
>
> try
>      {
>         Object delegate =
>                 FactoryFinder.find(JAXRS_RUNTIME_DELEGATE_PROPERTY,
>                         JAXRS_DEFAULT_RUNTIME_DELEGATE);
>         if (!(delegate instanceof RuntimeDelegate))
>         {
>            Class pClass = RuntimeDelegate.class;
>            String classnameAsResource = pClass.getName().replace('.', '/')
> + ".class";
>            ClassLoader loader = pClass.getClassLoader();
>            if (loader == null)
>            {
>               loader = ClassLoader.getSystemClassLoader();
>            }
>            URL targetTypeURL = loader.getResource(classnameAsResource);
>           throw new LinkageError("ClassCastException: attempting to cast" +
>
>  delegate.getClass().getClassLoader().getResource(classnameAsResource) +
>                    "to" + targetTypeURL.toString());
>         }
>         return (RuntimeDelegate) delegate;
>      }
>      catch (Exception ex)
>      {
>         throw new RuntimeException(ex);
>      }
>
> And here is my pom configuration:
>
> <plugin>
>                <groupId>org.codehaus.mojo</groupId>
>                <artifactId>failsafe-maven-plugin</artifactId>
>                <version>2.4.3-alpha-1</version>
>                <configuration>
>                    <useSystemClassLoader>false</useSystemClassLoader>
>                    <useManifestOnlyJar>false</useManifestOnlyJar>
>                    <forkMode>once</forkMode>
>                    <includes>
>
>  <include>**/CategoriesServiceDelegateIT.java</include>
>                    </includes>
>                </configuration>
>                <executions>
>                    <execution>
>                        <id>integration-test</id>
>                        <goals>
>                            <goal>integration-test</goal>
>                        </goals>
>                    </execution>
>                    <execution>
>                        <id>verify</id>
>                        <goals>
>                            <goal>verify</goal>
>                        </goals>
>                    </execution>
>                </executions>
> </plugin>
>
> When I set useSystemClassLoader to true, the ClassCastException goes away,
> but then nothing happens except for a hard exit. I see nothing in the logs
> or in failsafe-reports to tell me what happened.
>
> Any insight into why things work in Maven 2.20 but not in 3.02 is
> appreciated.
>
> Thanks.
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Classloader Problem with Maven 3.0.2

Posted by Anders Hammar <an...@hammar.net>.
You're using an old and deprecated version of the failsafe plugin. I don't
think it works with Maven 3.
failsafe-m-p is now found at Apache Maven (not Codehaus Mojo):
http://maven.apache.org/plugins/maven-failsafe-plugin/

Upgrade and retry!

/Anders

On Fri, Jan 14, 2011 at 20:27, Neil Chaudhuri
<nc...@potomacfusion.com>wrote:

> I have upgraded from Maven 2.20 to 3.02, and I found many of my integration
> tests that used to pass are now failing because of a ClassCastException,
> which is an odd exception to find when no code has changed. I traced the
> issue to a classloader problem with Maven 3 that arises in another Java
> library (RESTEasy if you were wondering).
>
> Here is their code:
>
> try
>      {
>         Object delegate =
>                 FactoryFinder.find(JAXRS_RUNTIME_DELEGATE_PROPERTY,
>                         JAXRS_DEFAULT_RUNTIME_DELEGATE);
>         if (!(delegate instanceof RuntimeDelegate))
>         {
>            Class pClass = RuntimeDelegate.class;
>            String classnameAsResource = pClass.getName().replace('.', '/')
> + ".class";
>            ClassLoader loader = pClass.getClassLoader();
>            if (loader == null)
>            {
>               loader = ClassLoader.getSystemClassLoader();
>            }
>            URL targetTypeURL = loader.getResource(classnameAsResource);
>           throw new LinkageError("ClassCastException: attempting to cast" +
>
>  delegate.getClass().getClassLoader().getResource(classnameAsResource) +
>                    "to" + targetTypeURL.toString());
>         }
>         return (RuntimeDelegate) delegate;
>      }
>      catch (Exception ex)
>      {
>         throw new RuntimeException(ex);
>      }
>
> And here is my pom configuration:
>
> <plugin>
>                <groupId>org.codehaus.mojo</groupId>
>                <artifactId>failsafe-maven-plugin</artifactId>
>                <version>2.4.3-alpha-1</version>
>                <configuration>
>                    <useSystemClassLoader>false</useSystemClassLoader>
>                    <useManifestOnlyJar>false</useManifestOnlyJar>
>                    <forkMode>once</forkMode>
>                    <includes>
>
>  <include>**/CategoriesServiceDelegateIT.java</include>
>                    </includes>
>                </configuration>
>                <executions>
>                    <execution>
>                        <id>integration-test</id>
>                        <goals>
>                            <goal>integration-test</goal>
>                        </goals>
>                    </execution>
>                    <execution>
>                        <id>verify</id>
>                        <goals>
>                            <goal>verify</goal>
>                        </goals>
>                    </execution>
>                </executions>
> </plugin>
>
> When I set useSystemClassLoader to true, the ClassCastException goes away,
> but then nothing happens except for a hard exit. I see nothing in the logs
> or in failsafe-reports to tell me what happened.
>
> Any insight into why things work in Maven 2.20 but not in 3.02 is
> appreciated.
>
> Thanks.
>