ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Gainty <mgai...@hotmail.com>
Subject RE: AW: Taskdef classloader issue: Solution found
Date Thu, 04 Jun 2009 12:26:50 GMT

Juergen and Team

dave is a very intelligent fellow whose solutions which can be rather complex always work
i am glad to hear he could provide a solution for this problem

Martin Gainty 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
 
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten
wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist
unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet
keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen
wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire
prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe
quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information
seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les
email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune
responsabilité pour le contenu fourni.




> Subject: AW: Taskdef classloader issue: Solution found 
> Date: Thu, 4 Jun 2009 13:45:33 +0200
> From: Juergen.Knuplesch@icongmbh.de
> To: user@ant.apache.org
> 
> Hello,
> 
> The real solution for my taskdef problem looks like:
> 
> David Wood writes about a similar problem and solved it by using:
> >
> >   // Get the task class loader we used to load this tag.
> >   AntClassLoader taskloader = (AntClassLoader)this.getClass().getClassLoader();
> >
> >   // Shove it into the Thread, replacing the thread's ClassLoader:
> >   taskloader.setThreadContextLoader();
> >
> > Then you do what you have to do. When your done, I highly advise doing a:
> >
> >   // Reset the Thread's original ClassLoader.
> >   taskloader.resetThreadContextLoader(); 
> 
> 
> So for certain tasks it is necessary to use the original classloader, that loaded the
task. 
> The code above replaces the classloader and the problem is solved!
> 
> Greetings Juergen
> 
> 
> -- 
> Jürgen Knuplesch
> -----Ursprüngliche Nachricht-----
> Von: Knuplesch, Juergen [mailto:Juergen.Knuplesch@icongmbh.de] 
> Gesendet: Dienstag, 2. Juni 2009 08:39
> An: Ant Users List
> Betreff: AW: Taskdef classloader issue
> 
> Hello Martin
> 
> Thanks for the deep insight and your help!
> I finally gave up, and used the workaround to put this special jar on the classpath of
ANT (instead of the classpath of taskdef).
> This works, but I do not really understand why.
> 
> Maybe I will find out after Pentacoast (how do you spell this?), if the Spirit of Debugging
comes over me.
> 
> Greetings Juergen
>  
> 
> 
> --
> Jürgen Knuplesch
> -----Ursprüngliche Nachricht-----
> Von: Martin Gainty [mailto:mgainty@hotmail.com]
> Gesendet: Freitag, 29. Mai 2009 17:27
> An: Ant Users List
> Betreff: RE: Taskdef classloader issue
> 
> 
> here is the testcase:
> 
> package org.apache.tools.ant;
> public class AntClassLoaderTest extends BuildFileTest {
> 
>     private Project p;
> 
>     public AntClassLoaderTest(String name) {
>         super(name);
>     }
> 
>     public void setUp() {
>         p = new Project();
>         p.init();
>         configureProject("src/etc/testcases/core/antclassloader.xml");
>         getProject().executeTarget("setup");
>     }
> 
>     public void tearDown() {
>         getProject().executeTarget("cleanup");
>     }
>     //test inspired by bug report 37085
>     public void testJarWithManifestInDirWithSpace() {
>         String mainjarstring = getProject().getProperty("main.jar");
>         String extjarstring = getProject().getProperty("ext.jar");
>         Path myPath = new Path(getProject());
>         myPath.setLocation(new File(mainjarstring));
>         getProject().setUserProperty("build.sysclasspath","ignore");
>         AntClassLoader myLoader = getProject().createClassLoader(myPath);
>         String path = myLoader.getClasspath();
>         assertEquals(mainjarstring + File.pathSeparator + extjarstring, path);
>     }
>     public void testJarWithManifestInNonAsciiDir() {
>         String mainjarstring = getProject().getProperty("main.jar.nonascii");
>         String extjarstring = getProject().getProperty("ext.jar.nonascii");
>         Path myPath = new Path(getProject());
>         myPath.setLocation(new File(mainjarstring));
>         getProject().setUserProperty("build.sysclasspath","ignore");
>         AntClassLoader myLoader = getProject().createClassLoader(myPath);
>         String path = myLoader.getClasspath();
>         assertEquals(mainjarstring + File.pathSeparator + extjarstring, path);
>     }
>     public void testCleanup() throws BuildException {
>         Path path = new Path(p, ".");
>         AntClassLoader loader = p.createClassLoader(path);
>         try {
>             // we don't expect to find this
>             loader.findClass("fubar");
>             fail("Did not expect to find fubar class");
>         } catch (ClassNotFoundException e) {
>             // ignore expected
>         }
> 
>         loader.cleanup();
>         try {
>             // we don't expect to find this
>             loader.findClass("fubar");
>             fail("Did not expect to find fubar class");
>         } catch (ClassNotFoundException e) {
>             // ignore expected
>         } catch (NullPointerException e) {
>             fail("loader should not fail even if cleaned up");
>         }
> 
>         // tell the build it is finished
>         p.fireBuildFinished(null);
>         try {
>             // we don't expect to find this
>             loader.findClass("fubar");
>             fail("Did not expect to find fubar class");
>         } catch (ClassNotFoundException e) {
>             // ignore expected
>         } catch (NullPointerException e) {
>             fail("loader should not fail even if project finished");
>         }
>     }
> }
> 
>         getProject().setUserProperty("build.sysclasspath","ignore");
> 
>         AntClassLoader myLoader = getProject().createClassLoader(myPath);
> build.sysclasspath
> The value of the build.sysclasspath property control how the system classpath, ie. the
classpath in effect when Ant is run, affects the behaviour of classpaths in Ant.
> The default behavior varies from Ant to Ant task.
> 
> 
> The values and their meanings are:
> 
> 
> 
> only
> Only the system classpath is used and classpaths specified in build files, etc are ignored.
This situation could be considered as the person running the build file knows more about the
environment than the person writing the build file
> 
> 
> 
> 
> ignore
> 
> The system classpath is ignored. This situation is the reverse of the above. The person
running the build trusts the build file writer to get the build file right
> 
> 
> 
> 
> last
> 
> The classpath is concatenated to any specified classpaths at the end. This is a compromise,
where the build file writer has priority.
> 
> 
> 
> 
> first
> 
> Any specified classpaths are concatenated to the system classpath. This is the other
form of compromise where the build runner has priority.
> setting build.sysclasspath to ignore allows your build file writer to have priority over
previous classpaths e.g.
> <project name="antclassloader-test" basedir=".">
> 
>     <!-- ant for germans -->
>     <property name="build.sysclasspath" value="ignore"/>
> 
> Viel Gluck!
> Martin
> ______________________________________________
> Verzicht und Vertraulichkeitanmerkung
>  
> Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so
bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer
Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und
entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails
koennen wir keine Haftung fuer den Inhalt uebernehmen.
> 
> 
> 
> 
> 
> 
> > Subject: Taskdef classloader issue
> > Date: Fri, 29 May 2009 16:40:35 +0200
> > From: Juergen.Knuplesch@icongmbh.de
> > To: user@ant.apache.org
> > 
> > Hello,
> > 
> > As I inspected the stacktrace, I found out that this exception could happen, when
you access a class with a classloader, that did not load the class.
> > 
> > So the taskdef loads the file. Is taskdef using a different classloader than the
classloade, who runs my task?
> > How can I use the same classloader for both?
> > 
> > Greetings Juergen
> > 
> > 
> > -- 
> > Jürgen Knuplesch                    www.icongmbh.de
> > icon Systemhaus GmbH                Tel. +49 711 806098-275
> > Sophienstraße 40                    
> > D-70178 Stuttgart                   Fax. +49 711 806098-299
> > 
> > Geschäftsführer: Uwe Seltmann
> > HRB Stuttgart 17655
> > USt-IdNr.: DE 811944121
> > -----Ursprüngliche Nachricht-----
> > Von: Knuplesch, Juergen [mailto:Juergen.Knuplesch@icongmbh.de]
> > Gesendet: Freitag, 29. Mai 2009 16:02
> > An: Ant Users List
> > Betreff: AW: Taskdef classpath still does not work - partIII
> > 
> > Hello,
> > 
> > Thanks for the suggestion, but sadly it did not work.
> > I created now a atcktrace:
> > 
> > java.lang.IllegalArgumentException: interface com.intland.codebeamer.remoting.RemoteApi
is not visible from class loader
> > 	at java.lang.reflect.Proxy.getProxyClass(Proxy.java:353)
> > 	at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:581)
> > 	at com.caucho.hessian.client.HessianProxyFactory.create(HessianProxyFactory.java:393)
> > 	at com.caucho.hessian.client.HessianProxyFactory.create(HessianProxyFactory.java:365)
> > 	at com.intland.codebeamer.remoting.RemoteApiFactory.create(RemoteApiFactory.java:69)
> > 	at com.intland.codebeamer.remoting.RemoteApiFactory.connect(RemoteApiFactory.java:86)
> > 	at de.icongmbh.codebeamer.CBUtilities.connect2CB(CBUtilities.java:55)
> > 	at de.icongmbh.codebeamer.CBUtilities.<init>(CBUtilities.java:42)
> > 	at de.icongmbh.build.updateinstalldb2cb.UploadInstallDB2CB.upload2CB(UploadInstallDB2CB.java:125)
> > 	at de.icongmbh.build.updateinstalldb2cb.UploadInstallDB2CB.updateInstallDSFinCB(UploadInstallDB2CB.java:224)
> > 	at de.icongmbh.build.updateinstalldb2cb.DeployInstallDBAntTask.execute(DeployInstallDBAntTask.java:41)
> > 	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
> > 	at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
> > 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > 	at java.lang.reflect.Method.invoke(Method.java:585)
> > 	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
> > 	at org.apache.tools.ant.Task.perform(Task.java:348)
> > 	at org.apache.tools.ant.Target.execute(Target.java:357)
> > 	at org.apache.tools.ant.Target.performTasks(Target.java:385)
> > 	at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
> > 	at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
> > 	at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
> > 	at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
> > 	at org.apache.tools.ant.Main.runBuild(Main.java:758)
> > 	at org.apache.tools.ant.Main.startAnt(Main.java:217)
> > 	at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
> > 	at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
> > 
> > 
> > I still cant see, what the problem is.
> > 
> > Greetings Jürgen
> > 
> > --
> > Jürgen Knuplesch
> > -----Ursprüngliche Nachricht-----
> > Von: Martin Gainty [mailto:mgainty@hotmail.com]
> > Gesendet: Freitag, 29. Mai 2009 15:23
> > An: Ant Users List
> > Betreff: RE: Taskdef classpath still does not work - partIII
> > 
> > 
> > können Sie versuchen:
> > 
> >     <path id="buildjava.path">
> >       <fileset dir="lib" includes="D:/nightlybuild/exportbaseHEAD/IconCodebeamerCVS/lib/*.jar"/>
> >     </path>
> > 
> >       <taskdef name="deployinstalldb"
> >                classname="de.icongmbh.build.updateinstalldb2cb.DeployInstallDBAntTask"
> >                onerror="report"
> >           loaderref="buildjava.path.loader" 
> > Mit Freundliche Gruben
> > Martin
> > Vereinigte Staaten
> > GMT+5 (diese Woche)
> > ______________________________________________
> > Verzicht und Vertraulichkeitanmerkung
> >  
> > Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein,
so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer
Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und
entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails
koennen wir keine Haftung fuer den Inhalt uebernehmen.
> > 
> > 
> > 
> > 
> > 
> > > Subject: Taskdef classpath still does not work - partIII
> > > Date: Fri, 29 May 2009 14:46:39 +0200
> > > From: Juergen.Knuplesch@icongmbh.de
> > > To: user@ant.apache.org
> > > 
> > > Hello,
> > > 
> > > My taskdef classpath still does not work (it sometimes worked).
> > > 
> > > I do the following
> > > 
> > >      <property name="taskdef.compareCvs2DopeDB.basepath" location="${cvs.exportboxbase}"/>
> > >      <getEclipseClasspath classpathid="buildjava.classpathid"
> > >                           workspace="${taskdef.compareCvs2DopeDB.basepath}"
> > >                           projectname="BuildJava" />
> > > 
> > >        
> > >      <taskdef name="deployinstalldb"
> > >               classname="de.icongmbh.build.updateinstalldb2cb.DeployInstallDBAntTask"
> > >               onerror="report"
> > >          loaderref="buildjava.path.loader" >
> > >        <classpath refid="buildjava.classpathid"/>
> > >      </taskdef>
> > > 
> > > In the end Ant tells me:
> > > BUILD FAILED
> > > D:\Entwicklung\Build\DopeBuildServer\dopebuild_ant2.xml:376: 
> > > java.lang.IllegalArgumentException: interface 
> > > com.intland.codebeamer.remoting.RemoteApi is not visible from class 
> > > loader
> > > 
> > > Total time: 14 seconds
> > > 
> > > It looks like sth. (cb-api.jar) Missing on the classpath.
> > > 
> > > But it is defintely in buildjava.classpathid.
> > > (Log:      [echo] |   |-- D:\nightlybuild\exportbaseHEAD\IconCodebeamerCVS\lib\cb-api.jar
)
> > > So the classloader of Ant can not find cb-api.jar although ist on the taskdef
classpath.
> > > 
> > > If I add this jar (D:\nightlybuild\exportbaseHEAD\IconCodebeamerCVS\lib\cb-api.jar)
to Ant it works.
> > > 
> > > This is crazy. Im working now a whole day on this topic and can not find a
reason.
> > > 
> > > Has anyone an idea, whats going on or how I can debug deeper what happens?
> > > 
> > > Greetings
> > > 
> > > Jürgen
> > > 
> > > --
> > > Jürgen Knuplesch
> > > -----Ursprüngliche Nachricht-----
> > > Von: Knuplesch, Juergen [mailto:Juergen.Knuplesch@icongmbh.de]
> > > Gesendet: Donnerstag, 28. Mai 2009 18:54
> > > An: Ant Users List
> > > Betreff: AW: AW: Taskdef classpath does not work - partII
> > > 
> > > Hello,
> > > 
> > > I use getEclipseClasspath to realize the classpath.
> > > If I run the class withot Ant inside Eclipse it works with the classpath I
defined in Eclipse.
> > > It also works if I add the jar to the Ant classpath.
> > > It does not work if I only use the Eclipse classpath for the taskdef together
with Ant.
> > > 
> > > The exception is:
> > > BUILD FAILED
> > > D:\Entwicklung\Build\DopeBuildServer\dopebuild_ant.xml:5794: 
> > > java.lang.IllegalArgumentException: interface 
> > > com.intland.codebeamer.remoting.RemoteApi is not visible from class 
> > > loader
> > > 
> > > 
> > > -- 
> > > Jürgen Knuplesch   
> > > -----Ursprüngliche Nachricht-----
> > > Von: Scot P. Floess [mailto:sfloess@nc.rr.com]
> > > Gesendet: Donnerstag, 28. Mai 2009 18:40
> > > An: Ant Users List
> > > Betreff: Re: AW: Taskdef classpath does not work - partII
> > > 
> > > 
> > > So, how do you construct your class path?
> > > 
> > > Also, what is the exception?
> > > 
> > > On Thu, 28 May 2009, Knuplesch, Juergen wrote:
> > > 
> > > > Hello,
> > > >
> > > > I have some additional information:
> > > >
> > > > My classpath is very long.
> > > > When I change the classpath order an exception happen somewhere else!
> > > >
> > > > Is there a restriction of the length of a classpath that will be handled
using taskdef?
> > > >
> > > > Greetings
> > > >
> > > > Jürgen
> > > >
> > > >
> > > > --
> > > > Jürgen Knuplesch
> > > >
> > > > -----Ursprüngliche Nachricht-----
> > > > Von: Knuplesch, Juergen [mailto:Juergen.Knuplesch@icongmbh.de]
> > > > Gesendet: Donnerstag, 28. Mai 2009 16:50
> > > > An: Ant Users List
> > > > Betreff: Taskdef classpath does nor work
> > > >
> > > > Hello,
> > > >
> > > > I do a taskdef with 1.7.1 like:
> > > >
> > > > <taskdef name="myTask"
> > > >    classname="myJavaClass">
> > > >   <classpath refid="java.classpathid"/>  </taskdef>
> > > >
> > > > When I display the classpath referenced in java.classpathid I see a certain
jar.
> > > > When I run the task it fails, because it can not find a class that is
based in that certain jar.
> > > >
> > > > When I add the jar in the classpath of Ant it works.
> > > >
> > > > This is strange, because lots of other classes and jars are found 
> > > > using this task. (The task starts does a lot and the final step
> > > > fails)
> > > >
> > > > Has Ant a problem with long classpaths or does it support only one 
> > > > classpath for all taskdefs???? (doesnt make sense to me)
> > > >
> > > > I can not find the reason. Please help!
> > > >
> > > > Greetings Jürgen
> > > >
> > > >
> > > > --
> > > > Jürgen Knuplesch
> > > >
> > > > ------------------------------------------------------------------
> > > > --
> > > > - To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For 
> > > > additional commands, e-mail: user-help@ant.apache.org
> > > >
> > > >
> > > > ------------------------------------------------------------------
> > > > --
> > > > - To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For 
> > > > additional commands, e-mail: user-help@ant.apache.org
> > > >
> > > >
> > > 
> > > Scot P. Floess
> > > 27 Lake Royale
> > > Louisburg, NC  27549
> > > 
> > > 252-478-8087 (Home)
> > > 919-890-8117 (Work)
> > > 
> > > Chief Architect JPlate   http://sourceforge.net/projects/jplate
> > > Chief Architect JavaPIM  http://sourceforge.net/projects/javapim
> > > 
> > > Architect Keros          http://sourceforge.net/projects/keros
> > > 
> > > --------------------------------------------------------------------
> > > - To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For 
> > > additional commands, e-mail: user-help@ant.apache.org
> > > 
> > > 
> > > --------------------------------------------------------------------
> > > - To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For 
> > > additional commands, e-mail: user-help@ant.apache.org
> > > 
> > 
> > _________________________________________________________________
> > Hotmail® has ever-growing storage! Don't worry about storage limits.
> > http://windowslive.com/Tutorial/Hotmail/Storage?ocid=TXT_TAGLM_WL_HM_T
> > utorial_Storage1_052009
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional 
> > commands, e-mail: user-help@ant.apache.org
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional 
> > commands, e-mail: user-help@ant.apache.org
> > 
> 
> _________________________________________________________________
> Hotmail® has a new way to see what's up with your friends.
> http://windowslive.com/Tutorial/Hotmail/WhatsNew?ocid=TXT_TAGLM_WL_HM_Tutorial_WhatsNew1_052009
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional commands, e-mail:
user-help@ant.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 

_________________________________________________________________
Lauren found her dream laptop. Find the PC that’s right for you.
http://www.microsoft.com/windows/choosepc/?ocid=ftp_val_wl_290
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message