You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Gervais <ge...@polymedis.com> on 2009/03/06 09:46:19 UTC
[Personnal task] Executing javac from a task container
Hi everybody,
I need to compile and package many jars (one jar per source folder). Because
I haven't found any task to do that, I have writing my own who extends
org.apache.tools.ant.Task and implements org.apache.tools.ant.TaskContainer.
She work great with tasks like "echo", "mkdir", "copy" but the "javac" task
is never executed. How can I run the "javac" task from a TaskContainer ?
Here is the main code and you can found the full class as attachment.
public void execute() throws BuildException {
if ( baseDir.isDirectory() ) {
for (File subdir : baseDir.listFiles(new DirectoryFilter()))
{
if ( getProject().getProperty(identifier)==null ) {
getProject().setNewProperty(identifier,
subdir.getName());
} else {
getProject().setProperty(identifier,
subdir.getName());
}
for (Task subtask : tasks) {
log("> Run task "+subtask.getTaskName());
subtask.perform();
}
}
} else {
log("Base directory \""+baseDir+"\". isn't a directory.",
0);
}
}
And finally the task content :
<foreach
basedir="${manager.location}${file.separator}${manager.moddir}"
identifier="modulename">
<echo level="info">Building module
${modulename}</echo>
<mkdir
dir="${modsdir}${file.separator}sicsmod-${modulename}"/>
<javac
srcdir="${manager.location}${file.separator}${manager.moddir}${file.separato
r}${modulename}"
destdir="${modsdir}${file.separator}sicsmod-${modulename}"
classpathref="manager.modules.classpath"
classpath="${build}${file.separator}${manager.jarname}"
includes="${manager.modules}/**"
debug="on" />
<!-- Copy each properties files (resources) and
images -->
<copy
todir="${modsdir}${file.separator}sicsmod-${modulename}">
<fileset
dir="${manager.location}${file.separator}${manager.moddir}${file.separator}$
{modulename}"
includes="**/*.properties,
**/*.png" />
</copy>
</foreach>
Thanks
__________ Information from ESET NOD32 Antivirus, version of virus signature
database 3912 (20090306) __________
The message was checked by ESET NOD32 Antivirus.
http://www.eset.com
RE: [Personnal task] Executing javac from a task container
Posted by Gervais <ge...@polymedis.com>.
Hello,
Thank you for response. I have found the problem this week-end. As you said,
I have something wrong in my "javac" task. Now all work great.
My custom task walk (no recursively) trough a folder who contains many
source folders (each folder contains a module for a main app), set a
property who contains the source folder name and execute each "subtasks" who
compile sources collect resources and make a jar using the property to
create the path and the jar name.
It seems that the "subant" task can achieve what I do with my custom task
but I no (already) know this task.
Thank your really much. Now I know the "subant" task and the tip to launch
"ant -v".
-----Message d'origine-----
De : Antoine Levy Lambert [mailto:antoine@gmx.de]
Envoyé : vendredi 6 mars 2009 23:27
À : Ant Users List
Objet : Re: [Personnal task] Executing javac from a task container
Hello Gervais,
out of my head I do not see anything specific about the javac task which
would restrict its usage. Maybe you are just not passing to it the
location of a directory containing source files due to a scripting
error, or a mis-assumption about where the source directories are.
What I do not understand clearly from your email is how do your custom
task and your build file interact ?
To find out in detail what is happening with javac, you could run your
build in verbose mode. (ant -v)
The classical way to compile and package many jars would be to :
- either create one build file per source folder,
- have these folder specific build files import a generic build file in
one location which can work for each source folder,
- then use the <subant/> task to iterate through the source folders
Regards,
Antoine
Gervais wrote:
> Hi everybody,
>
> I need to compile and package many jars (one jar per source folder).
Because
> I haven't found any task to do that, I have writing my own who extends
> org.apache.tools.ant.Task and implements
org.apache.tools.ant.TaskContainer.
>
> She work great with tasks like "echo", "mkdir", "copy" but the "javac"
task
> is never executed. How can I run the "javac" task from a TaskContainer ?
>
> Here is the main code and you can found the full class as attachment.
> public void execute() throws BuildException {
> if ( baseDir.isDirectory() ) {
> for (File subdir : baseDir.listFiles(new DirectoryFilter()))
> {
> if ( getProject().getProperty(identifier)==null ) {
> getProject().setNewProperty(identifier,
> subdir.getName());
> } else {
> getProject().setProperty(identifier,
> subdir.getName());
> }
>
> for (Task subtask : tasks) {
> log("> Run task "+subtask.getTaskName());
> subtask.perform();
> }
> }
> } else {
> log("Base directory \""+baseDir+"\". isn't a directory.",
> 0);
> }
> }
>
> And finally the task content :
> <foreach
> basedir="${manager.location}${file.separator}${manager.moddir}"
> identifier="modulename">
> <echo level="info">Building module
> ${modulename}</echo>
> <mkdir
> dir="${modsdir}${file.separator}sicsmod-${modulename}"/>
> <javac
>
srcdir="${manager.location}${file.separator}${manager.moddir}${file.separato
> r}${modulename}"
>
> destdir="${modsdir}${file.separator}sicsmod-${modulename}"
>
> classpathref="manager.modules.classpath"
>
> classpath="${build}${file.separator}${manager.jarname}"
> includes="${manager.modules}/**"
> debug="on" />
> <!-- Copy each properties files (resources) and
> images -->
> <copy
> todir="${modsdir}${file.separator}sicsmod-${modulename}">
> <fileset
>
dir="${manager.location}${file.separator}${manager.moddir}${file.separator}$
> {modulename}"
> includes="**/*.properties,
> **/*.png" />
> </copy>
> </foreach>
>
> Thanks
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus
signature
> database 3912 (20090306) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>
> ------------------------------------------------------------------------
>
> ---------------------------------------------------------------------
> 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
__________ Information from ESET NOD32 Antivirus, version of virus signature
database 3918 (20090309) __________
The message was checked by ESET NOD32 Antivirus.
http://www.eset.com
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: [Personnal task] Executing javac from a task container
Posted by Antoine Levy Lambert <an...@gmx.de>.
Hello Gervais,
out of my head I do not see anything specific about the javac task which
would restrict its usage. Maybe you are just not passing to it the
location of a directory containing source files due to a scripting
error, or a mis-assumption about where the source directories are.
What I do not understand clearly from your email is how do your custom
task and your build file interact ?
To find out in detail what is happening with javac, you could run your
build in verbose mode. (ant -v)
The classical way to compile and package many jars would be to :
- either create one build file per source folder,
- have these folder specific build files import a generic build file in
one location which can work for each source folder,
- then use the <subant/> task to iterate through the source folders
Regards,
Antoine
Gervais wrote:
> Hi everybody,
>
> I need to compile and package many jars (one jar per source folder). Because
> I haven't found any task to do that, I have writing my own who extends
> org.apache.tools.ant.Task and implements org.apache.tools.ant.TaskContainer.
>
> She work great with tasks like "echo", "mkdir", "copy" but the "javac" task
> is never executed. How can I run the "javac" task from a TaskContainer ?
>
> Here is the main code and you can found the full class as attachment.
> public void execute() throws BuildException {
> if ( baseDir.isDirectory() ) {
> for (File subdir : baseDir.listFiles(new DirectoryFilter()))
> {
> if ( getProject().getProperty(identifier)==null ) {
> getProject().setNewProperty(identifier,
> subdir.getName());
> } else {
> getProject().setProperty(identifier,
> subdir.getName());
> }
>
> for (Task subtask : tasks) {
> log("> Run task "+subtask.getTaskName());
> subtask.perform();
> }
> }
> } else {
> log("Base directory \""+baseDir+"\". isn't a directory.",
> 0);
> }
> }
>
> And finally the task content :
> <foreach
> basedir="${manager.location}${file.separator}${manager.moddir}"
> identifier="modulename">
> <echo level="info">Building module
> ${modulename}</echo>
> <mkdir
> dir="${modsdir}${file.separator}sicsmod-${modulename}"/>
> <javac
> srcdir="${manager.location}${file.separator}${manager.moddir}${file.separato
> r}${modulename}"
>
> destdir="${modsdir}${file.separator}sicsmod-${modulename}"
>
> classpathref="manager.modules.classpath"
>
> classpath="${build}${file.separator}${manager.jarname}"
> includes="${manager.modules}/**"
> debug="on" />
> <!-- Copy each properties files (resources) and
> images -->
> <copy
> todir="${modsdir}${file.separator}sicsmod-${modulename}">
> <fileset
> dir="${manager.location}${file.separator}${manager.moddir}${file.separator}$
> {modulename}"
> includes="**/*.properties,
> **/*.png" />
> </copy>
> </foreach>
>
> Thanks
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus signature
> database 3912 (20090306) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>
> ------------------------------------------------------------------------
>
> ---------------------------------------------------------------------
> 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