You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Sean Radford <sr...@aegeus-technology.com> on 2003/02/04 18:00:56 UTC

Re: ClassCastException running a junit test

I should add that the only location of the problem Class is in a jar in
my local maven repository and referenced as a project dependency.

>Hi,
>
>Can anyone help with this.
>
>When one of my unit tests run I get a ClassCastExbeption. It shouldn't
>as the instance it is casting is of the correct type. What appears to
>be
>the problem is that the Class the test class is casting to is on a
>different classloader:
>
>ClassLoader for instance: org.apache.tools.ant.AntClassLoader@127461b
>ClassLoader for class to cast to:
>org.apache.tools.ant.AntClassLoader@39da8a
>
>Any ideas? (I've seen similar but not the same problems on the list)
>

Regards,

Sean

-- 
Sean Radford <sr...@aegeus-technology.com>
Aegeus Technology Ltd


Re: ClassCastException running a junit test

Posted by Jason van Zyl <ja...@zenplex.com>.
On Tue, 2003-02-04 at 15:07, Incze Lajos wrote:
> On Tue, Feb 04, 2003 at 05:00:56PM +0000, Sean Radford wrote:
> > I should add that the only location of the problem Class is in a jar in
> > my local maven repository and referenced as a project dependency.
> > 
> 
> Not sure, that this is your problem, but try to add in project.xml to
> that dependency the classloader property "root.maven":
> 
>     <dependency>
>       <id>YOUR_ID</id>
>       <version>YOUR_VERSION</version>
>       <url>YOUR_URL</url>
>       <properties>
>         <classloader>root.maven</classloader>
>       </properties>
>     </dependency>

This is not required. Anything listed in your dependencies should now be
available to your executing maven.xml scripts.

> incze
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-maven-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-maven-user-help@jakarta.apache.org
-- 
jvz.

Jason van Zyl
jason@zenplex.com
http://tambora.zenplex.org

In short, man creates for himself a new religion of a rational
and technical order to justify his work and to be justified in it.
  
  -- Jacques Ellul, The Technological Society


Re: ClassCastException running a junit test

Posted by Sean Radford <sr...@bladesystems.co.uk>.
Well, tried just dumping my jar into 'jre_home/lib/ext' but that caused
other problems. So played around with some things and still having other
problems which will require major tinkering with my jar and class
structures.

So tried the Forehead option - to no avail. My classes don't seem to be
found at all. The project won't even compile as can't find my classes
that are in the jar I've added to Forehead.

Hmm... Should also add that with everything as I started out (with my
jars just as dependencies), if I do a 'maven eclipse:generate-project'
and then run my junit test from within eclipse all is well...

Grrrgghhh. Any further ideas?

Thanks in advance,

Sean

On Wed, 2003-02-05 at 00:20, Incze Lajos wrote:
> On Tue, Feb 04, 2003 at 10:56:26PM +0000, Sean Radford wrote:
> > Had already tried that, with no difference. I also noticed that the
> > properties tag is not in the project xsd file and so assumed that this
> > is now defunct.
> > 
> > The class that is causing the problem is my own Certificate class (a
> > class that implements java.security.cert.Certificate) and is obtained
> > via the java.security.cert.CertificateFactory which creates the
> > instance. I'm assuming that the classloader for my jar (with the
> > Certificate and Provider) is being loaded by a (lower) classloader that
> > the JRE CertificateFactory can't see and so it is re-loading my jar onto
> > its classloader. Thus, later on I get the ClassCastException. So I'm
> > guessing I need to somehow get junit/maven to load my jar into a higher
> > classloader? (I'm no expert on these classloader things by the way!)
> > 
> > Any help much appreciated.
> > 
> > Sean
> > 
> 
> If you want to test your guess, then you can load your class into
> the root clasloader by entering your jar into the $MAVEN_HOME/bin/forehead.conf 
> file. Or if your certificate implementation should be used obligatorily
> sitewide you can even place your jar into the jre_home/lib/ext directory, 
> and it'll become available to any java programs as part of the language runtime.
> 
> incze
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-maven-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-maven-user-help@jakarta.apache.org
-- 
Sean Radford <sr...@bladesystems.co.uk>
Blade Systems


Re: ClassCastException running a junit test

Posted by Incze Lajos <in...@mail.matav.hu>.
On Tue, Feb 04, 2003 at 10:56:26PM +0000, Sean Radford wrote:
> Had already tried that, with no difference. I also noticed that the
> properties tag is not in the project xsd file and so assumed that this
> is now defunct.
> 
> The class that is causing the problem is my own Certificate class (a
> class that implements java.security.cert.Certificate) and is obtained
> via the java.security.cert.CertificateFactory which creates the
> instance. I'm assuming that the classloader for my jar (with the
> Certificate and Provider) is being loaded by a (lower) classloader that
> the JRE CertificateFactory can't see and so it is re-loading my jar onto
> its classloader. Thus, later on I get the ClassCastException. So I'm
> guessing I need to somehow get junit/maven to load my jar into a higher
> classloader? (I'm no expert on these classloader things by the way!)
> 
> Any help much appreciated.
> 
> Sean
> 

If you want to test your guess, then you can load your class into
the root clasloader by entering your jar into the $MAVEN_HOME/bin/forehead.conf 
file. Or if your certificate implementation should be used obligatorily
sitewide you can even place your jar into the jre_home/lib/ext directory, 
and it'll become available to any java programs as part of the language runtime.

incze

Re: ClassCastException running a junit test

Posted by Sean Radford <sr...@bladesystems.co.uk>.
Had already tried that, with no difference. I also noticed that the
properties tag is not in the project xsd file and so assumed that this
is now defunct.

The class that is causing the problem is my own Certificate class (a
class that implements java.security.cert.Certificate) and is obtained
via the java.security.cert.CertificateFactory which creates the
instance. I'm assuming that the classloader for my jar (with the
Certificate and Provider) is being loaded by a (lower) classloader that
the JRE CertificateFactory can't see and so it is re-loading my jar onto
its classloader. Thus, later on I get the ClassCastException. So I'm
guessing I need to somehow get junit/maven to load my jar into a higher
classloader? (I'm no expert on these classloader things by the way!)

Any help much appreciated.

Sean





On Tue, 2003-02-04 at 20:07, Incze Lajos wrote:
> On Tue, Feb 04, 2003 at 05:00:56PM +0000, Sean Radford wrote:
> > I should add that the only location of the problem Class is in a jar in
> > my local maven repository and referenced as a project dependency.
> > 
> 
> Not sure, that this is your problem, but try to add in project.xml to
> that dependency the classloader property "root.maven":
> 
>     <dependency>
>       <id>YOUR_ID</id>
>       <version>YOUR_VERSION</version>
>       <url>YOUR_URL</url>
>       <properties>
>         <classloader>root.maven</classloader>
>       </properties>
>     </dependency>
> 
> incze
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-maven-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-maven-user-help@jakarta.apache.org
-- 
Sean Radford <sr...@bladesystems.co.uk>
Blade Systems


Re: ClassCastException running a junit test

Posted by Incze Lajos <in...@mail.matav.hu>.
On Tue, Feb 04, 2003 at 05:00:56PM +0000, Sean Radford wrote:
> I should add that the only location of the problem Class is in a jar in
> my local maven repository and referenced as a project dependency.
> 

Not sure, that this is your problem, but try to add in project.xml to
that dependency the classloader property "root.maven":

    <dependency>
      <id>YOUR_ID</id>
      <version>YOUR_VERSION</version>
      <url>YOUR_URL</url>
      <properties>
        <classloader>root.maven</classloader>
      </properties>
    </dependency>

incze