Java Mailing List Archive

http://www.ant-tasks.com/

Apache Ant Archive

» Ant Users List
» Ant Developers List
Jar Locking

Jar Locking

2006-08-31       - By Stephen McConnell
Reply:     1     2     3     4     5     6     7     8     9     10     >>  



> -----Original Message-----
> From: Marc Farrow [mailto:marc.farrow@(protected)]
> Sent: Friday, 1 September 2006 2:35 AM
> To: Ant Users List
> Subject: Re: Jar Locking
>
> Thanks Stephen.  If I set all references to Ant to null and
> forced GC, would that resolve the problem?

Well, umm, this is tricky.  If your loading a task or data type definition I
think Ant holds a strong reference to the class which would suggest that
setting things to null would not change (because strong references are held
for the life of the JVM).  I may be wrong here because it's been a while
since I dug into Ant internals on task class references - but one of the Ant
Developers could probably confirm things.  

However, if your running Ant as an embedded solution - then in principal the
disposal of the Ant project would clear any task and datatype references and
you may have a chance.  But this is tricky stuff and getting it right really
requires that the Ant project and all Ant related stuff is loaded in a child
classloader relative to the launching application (i.e. it's the classloader
disposal that is key to the releasing of the file reference).  

It is possible - but it's not trivial.

Cheers, Steve.



>
> On 8/31/06, Stephen McConnell <mcconnell@(protected)> wrote:
> >
> >
> >
> > > -----Original Message-----
> > > From: Marc Farrow [mailto:marc.farrow@(protected)]
> > > Sent: Thursday, 31 August 2006 6:13 AM
> > > To: ant-user
> > > Subject: Jar Locking
> > >
> > > Everytime I run an ant task (either in NetBeans or from
> within Java
> > > Code), the executing jar gets locked and I cannot delete
> the jar.  I
> > > am copying the ant script and the dependent jar that it
> needs to run
> > > and then executing the ant tasks.  Then I wish to delete
> the "new"
> > > copy I just created to run, but a jar I am using is
> locked and will
> > > not allow me.
> > >  This in on a Windows 2000 machine.
> >
> > The jar file is locked because it is referenced in a
> classloader.  The
> > lock will be released once the classloader is garbage collected but
> > that will not happen until all references to all classes defined by
> > the jar are no longer referenced.  If the jar file in question is
> > referenced by Ant then chances are that your file will not
> be released
> > until the Ant Project instance is no longer in use.
> >
> > The solution to the problem is to handle the creation and updating
> > operations under two distinct projects.  One project handles the
> > creation of a new jar file, and the second project handles the
> > replication of the jar (with the assumption that your
> second project
> > does not include a classpath reference to the jar file).
> >
> > Cheers, Steve.
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@(protected) For
> additional
> > commands, e-mail: user-help@(protected)
> >
> >
>
>
> --
> Marc Farrow
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)


©2008 ant-tasks.com - Jax Systems, LLC, U.S.A.