any reason why you can't use two different class loaders? something like:

public static boolean sameUID(String classname, File oldJar, File newJar) {
     URL[] oldClasspath = new URL[] { oldJar.toURL() };
     URL[] newClasspath = new URL[] { newJar.toURL() };

     URLClassLoader oldLoader = new URLClassLoader(oldClasspath);
     URLClassLoader newLoader = new URLClassLoader(newClasspath);

     Class oldClass = oldLoader.loadClass(classname);
     Class newClass = newLoader.loadClass(classname);

     long oldUID = ObjectStreamClass.lookup(oldClass).getSerialVersionUID
();
     long newUID = ObjectStreamClass.lookup(newClass).getSerialVersionUID
();

     return oldUID = newUID;
}

As long as neither of the jars are in the original ant classpath, this
should work, I think. Otherwise, both class loaders will return the one in
the main classpath (they always check the system classpath first).

I haven't played with UID's much, so I could be way off...



                                                                                
                                                              
                    "Jim Stiefel"                                               
                                                              
                    <jim.stiefel@        To:     <[EMAIL PROTECTED]>            
                                                     
                    cubus.net>           cc:                                    
                                                              
                                         Subject:     task with arbitrary 
classpath                                                           
                    06/13/00                                                    
                                                              
                    04:52 PM                                                    
                                                              
                    Please                                                      
                                                              
                    respond to                                                  
                                                              
                    ant-dev                                                     
                                                              
                                                                                
                                                              
                                                                                
                                                              




I am faced with an interesting problem I hope someone with more
experience with ant might be able to help me solve.  I want to define a
new ant task that will compare serial version UID's of freshly compiled
classes to the same class files in a known baseline jar so that my build
process can flag problems in serialization compatibility between our
development version and our last release version.

Retrieving the Serial Version UID is easy enough using
java.io.ObjectStreamClass. The challenge is that the operation needs to
be run twice with different classpaths.  In one case,  the classpath
needs to include the baseline jar,  while in the second case,  it needs
to include the newly built jar.

Can someone suggest a simple or elegant way to accomplish this?

Thanks,
 Jim




Reply via email to