You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Robert Virkus <ro...@enough.de> on 2005/02/25 17:13:59 UTC

Duplicate Class Error when Re-using Javac Task

Hi everyone,

I'd like to re-use a Javac-task from within my own task but I always get 
"duplicate class: ClassName"-errors when I compile the second set of source 
code files.

The background of this is that I have a preprocessor that creates different 
source code versions of the same project, which are then compiled by the 
org.apache.tools.ant.taskdefs.Javac task. I use and set different directories 
for the source code and for the compiled classes in each run. The first round 
is compiled without any problems, but the following round fails with the 
"duplicate class" error.

When I create a new instance of the Javac task, it works without problems. 

I want to reuse the Javac task since I want to allow a nested 
<javac>-definition in my task (in the build.xml). (The project is J2ME Polish 
by the way, www.j2mepolish.org).

Is anyone aware what could be done in this case? I have seen that the Javac 
task resets its internal file list for each execute() call, but this doesn't 
seem to help. I could send a demonstrator project along with the source code 
to anyone interested.

Thanks in advance,
    Robert
-- 
Robert Virkus
Enough Software
Vor dem Steintor 218
28203 Bremen
Germany

www.enough.de
+49-(0)421-9889131
+49-(0)160-7788203
robert@enough.de

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: Duplicate Class Error when Re-using Javac Task

Posted by Robert Virkus <ro...@enough.de>.
Hi Martin,

sorry, I forgot to mention that - fork does not help neither.

Thanks,
    Robert

On Friday 25 February 2005 18:51, Martin Gainty wrote:
> Robert
> Did you enable the javac task fork="true"
> Viel Gluck,
> Martin-
> ----- Original Message -----
> From: "Robert Virkus" <ro...@enough.de>
> To: "Ant Developers List" <de...@ant.apache.org>
> Sent: Friday, February 25, 2005 11:13 AM
> Subject: Duplicate Class Error when Re-using Javac Task
>
> > Hi everyone,
> >
> > I'd like to re-use a Javac-task from within my own task but I always get
> > "duplicate class: ClassName"-errors when I compile the second set of
> > source
> > code files.
> >
> > The background of this is that I have a preprocessor that creates
> > different
> > source code versions of the same project, which are then compiled by the
> > org.apache.tools.ant.taskdefs.Javac task. I use and set different
> > directories
> > for the source code and for the compiled classes in each run. The first
> > round
> > is compiled without any problems, but the following round fails with the
> > "duplicate class" error.
> >
> > When I create a new instance of the Javac task, it works without
> > problems.
> >
> > I want to reuse the Javac task since I want to allow a nested
> > <javac>-definition in my task (in the build.xml). (The project is J2ME
> > Polish
> > by the way, www.j2mepolish.org).
> >
> > Is anyone aware what could be done in this case? I have seen that the
> > Javac
> > task resets its internal file list for each execute() call, but this
> > doesn't
> > seem to help. I could send a demonstrator project along with the source
> > code
> > to anyone interested.
> >
> > Thanks in advance,
> >    Robert
> > --
> > Robert Virkus
> > Enough Software
> > Vor dem Steintor 218
> > 28203 Bremen
> > Germany
> >
> > www.enough.de
> > +49-(0)421-9889131
> > +49-(0)160-7788203
> > robert@enough.de
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> > For additional commands, e-mail: dev-help@ant.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org

-- 
Robert Virkus
Enough Software
Vor dem Steintor 218
28203 Bremen
Germany

www.enough.de
+49-(0)421-9889131
+49-(0)160-7788203
robert@enough.de

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: Duplicate Class Error when Re-using Javac Task

Posted by Martin Gainty <mg...@hotmail.com>.
Robert
Did you enable the javac task fork="true"
Viel Gluck,
Martin-
----- Original Message ----- 
From: "Robert Virkus" <ro...@enough.de>
To: "Ant Developers List" <de...@ant.apache.org>
Sent: Friday, February 25, 2005 11:13 AM
Subject: Duplicate Class Error when Re-using Javac Task


> Hi everyone,
>
> I'd like to re-use a Javac-task from within my own task but I always get
> "duplicate class: ClassName"-errors when I compile the second set of 
> source
> code files.
>
> The background of this is that I have a preprocessor that creates 
> different
> source code versions of the same project, which are then compiled by the
> org.apache.tools.ant.taskdefs.Javac task. I use and set different 
> directories
> for the source code and for the compiled classes in each run. The first 
> round
> is compiled without any problems, but the following round fails with the
> "duplicate class" error.
>
> When I create a new instance of the Javac task, it works without problems.
>
> I want to reuse the Javac task since I want to allow a nested
> <javac>-definition in my task (in the build.xml). (The project is J2ME 
> Polish
> by the way, www.j2mepolish.org).
>
> Is anyone aware what could be done in this case? I have seen that the 
> Javac
> task resets its internal file list for each execute() call, but this 
> doesn't
> seem to help. I could send a demonstrator project along with the source 
> code
> to anyone interested.
>
> Thanks in advance,
>    Robert
> -- 
> Robert Virkus
> Enough Software
> Vor dem Steintor 218
> 28203 Bremen
> Germany
>
> www.enough.de
> +49-(0)421-9889131
> +49-(0)160-7788203
> robert@enough.de
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: Duplicate Class Error when Re-using Javac Task

Posted by Stefan Bodewig <bo...@apache.org>.
On Sun, 27 Feb 2005, Stefan Bodewig <bo...@apache.org> wrote:
> On Sat, 26 Feb 2005, Robert Virkus <ro...@enough.de> wrote:

>> The bootclasspath, however, is appended (the first device is a
>> MIDP/1.0 device, the second one a MIDP/2.0 one), so in the second
>> round I have something like this:
>> 
>> BootClasspath=/home/enough/workspace/enough-polish-build/import/midp1.jar:/home/enough/workspace/enough-polish-build/import/midp2.jar
> 
> I'll look into this.

Could you please give a recent nightly build a try?  I think I've
found the place where the bootclasspath got modified in the compiler
adapter but that should have been fixed as a side-effect of another
change.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: Duplicate Class Error when Re-using Javac Task

Posted by Stefan Bodewig <bo...@apache.org>.
On Sat, 26 Feb 2005, Robert Virkus <ro...@enough.de> wrote:

> the classpath is fine, but it isn't set for the two target devices
> anyhow - so in both rounds it is empty.

That's good news.

> The bootclasspath, however, is appended (the first device is a
> MIDP/1.0 device, the second one a MIDP/2.0 one), so in the second
> round I have something like this:
> 
> BootClasspath=/home/enough/workspace/enough-polish-build/import/midp1.jar:/home/enough/workspace/enough-polish-build/import/midp2.jar

I'll look into this.

> This is not causing the current trouble (since all the "duplicate
> class"-errors are in neither of both JAR files),

so where are they?

Ant should log the command line it passes to javac at the verbose
level, does it look suspicious.

> So re-using the Javac task seems not to be possible. 

Maybe we can fix it,

> So what could I do?

Right now, I wouldn't give up on fixing the task.

> I now would create a "wrapper"-task that accepts all attributes as
> well as nested elements just like the Javac task, so that I could
> instantiate a fresh Javac for each round.

This basically is what Dominique talked about when he said it would be
best if you could get hold of the UnknownElement (which is just that
wrapper, but written and populated by Ant).  Even if there might now
be a way to get hold of an UnknownElement directly (I'm not sure, it
may be possible), you can use it as your wrapper and populate it
yourself.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: Duplicate Class Error when Re-using Javac Task

Posted by Robert Virkus <ro...@enough.de>.
Hi Stefan, Dominique, and all,

the classpath is fine, but it isn't set for the two target devices anyhow - so 
in both rounds it is empty. The bootclasspath, however, is appended (the 
first device is a MIDP/1.0 device, the second one a MIDP/2.0 one), so in the 
second round I have something like this:

BootClasspath=/home/enough/workspace/enough-polish-build/import/midp1.jar:/home/enough/workspace/enough-polish-build/import/midp2.jar

whereas in the first round this is set:

BootClasspath=/home/enough/workspace/enough-polish-build/import/midp1.jar

This is not causing the current trouble (since all the "duplicate 
class"-errors are in neither of both JAR files), though it will propably 
become a problem later onwards.

So re-using the Javac task seems not to be possible. 

So what could I do? I now would create a "wrapper"-task that accepts all 
attributes as well as nested elements just like the Javac task, so that I 
could instantiate a fresh Javac for each round. Apart from the necessary work 
this approach means that I have to update the wrapper-task each time the 
Javac task is changed. So is there a better approach? For such cases I'd love 
to see a generic Task.newTaskInstance()...  method ;-)

Thanks again,
    Robert



On Friday 25 February 2005 21:35, Stefan Bodewig wrote:
> On Fri, 25 Feb 2005, Robert Virkus <ro...@enough.de> wrote:
> > The background of this is that I have a preprocessor that creates
> > different source code versions of the same project, which are then
> > compiled by the org.apache.tools.ant.taskdefs.Javac task. I use and
> > set different directories for the source code and for the compiled
> > classes in each run. The first round is compiled without any
> > problems, but the following round fails with the "duplicate class"
> > error.
>
> Sounds as if the defined classpath gets poluted with your source
> directory.  Can you compare the result of Javac#getClasspath before
> and after invoking execute?
>
> Stefan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org

-- 
Robert Virkus
Enough Software
Vor dem Steintor 218
28203 Bremen
Germany

www.enough.de
+49-(0)421-9889131
+49-(0)160-7788203
robert@enough.de

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: Duplicate Class Error when Re-using Javac Task

Posted by Stefan Bodewig <bo...@apache.org>.
On Fri, 25 Feb 2005, Robert Virkus <ro...@enough.de> wrote:

> The background of this is that I have a preprocessor that creates
> different source code versions of the same project, which are then
> compiled by the org.apache.tools.ant.taskdefs.Javac task. I use and
> set different directories for the source code and for the compiled
> classes in each run. The first round is compiled without any
> problems, but the following round fails with the "duplicate class"
> error.

Sounds as if the defined classpath gets poluted with your source
directory.  Can you compare the result of Javac#getClasspath before
and after invoking execute?

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org