Pessoal,
como eu consigo executar uma Task a cada arquivo de um diretório com o Ant?
executar a taskPessoal,
como eu consigo executar uma Task a cada arquivo de um diretório com o Ant?
executar a taskUsando as tasks do Ant-contrib você pode usar o for, com ant puro eu não sei não:
Então,
eu tentei fazer esse negócio funcionar, mas não deu. Veja meu teste:
<?xml version="1.0"?>
<project default="main" basedir=".">
<echo message="Teste com o FOR"/>
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="${basedir}\WebContent\WEB-INF\lib\ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<for list="a,b,c,d,e" param="letter">
<sequential>
<echo>Letter @{letter}</echo>
</sequential>
</for>
<target name="main" >
</target>
</project>
Da o seguinte erro:
Buildfile: D:\Desenv\workspace_ant\nossoken\testeBuild.xml
[echo] Teste com o FOR
BUILD FAILED
D:\Desenv\workspace_ant\nossoken\testeBuild.xml:13: Could not create task or type of type: for.
Ant could not find the task or a class this task relies upon.
This is common and has a number of causes; the usual
solutions are to read the manual pages then download and
install needed JAR files, or fix the build file:
- You have misspelt 'for'.
Fix: check your spelling.
- The task needs an external JAR file to execute
and this is not found at the right place in the classpath.
Fix: check the documentation for dependencies.
Fix: declare the task.
- The task is an Ant optional task and the JAR file and/or libraries
implementing the functionality were not found at the time you
yourself built your installation of Ant from the Ant sources.
Fix: Look in the ANT_HOME/lib for the 'ant-' JAR corresponding to the
task and make sure it contains more than merely a META-INF/MANIFEST.MF.
If all it contains is the manifest, then rebuild Ant with the needed
libraries present in ${ant.home}/lib/optional/ , or alternatively,
download a pre-built release version from apache.org
- The build file was written for a later version of Ant
Fix: upgrade to at least the latest release version of Ant
- The task is not an Ant core or optional task
and needs to be declared using <taskdef>.
- You are attempting to use a task defined using
<presetdef> or <macrodef> but have spelt wrong or not
defined it at the point of use
Remember that for JAR files to be visible to Ant tasks implemented
in ANT_HOME/lib, the files must be in the same directory or on the
classpath
Please neither file bug reports on this problem, nor email the
Ant mailing lists, until all of these causes have been explored,
as this is not an Ant bug.
Total time: 282 milliseconds
Que besteira eu estou fazendo?
Mude:
Para:
Legal !
funcionou!
Obrigado!
Agora tenho que fazer isso com uma lista de arquivos… vou me divertir mais um pouco!
Pessoal,
preciso de mais uma força. Olha só, eu consegui montar lista e o “For”, só que agora eu preciso trabalhar a variável para ter somente o nome da classe java, bom tem duas formas que eu imagino serem possíveis, uma delas seria obter o nome da classe através do arquivo .java, e a outra (que eu não simpatizo muito) seria trabalhar a variável com substring. Vejam o código do ANT:
<?xml version="1.0"?>
<project default="main" basedir=".">
<echo message="Teste com o FOR"/>
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${basedir}\WebContent\WEB-INF\lib\ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<for param="file">
<path>
<fileset dir="c:\temp" includes="*.java"/>
</path>
<sequential>
<echo>@{file}</echo>
</sequential>
</for>
<target name="main" >
</target>
</project>
e essa é a saída:
Buildfile: D:\Desenv\workspace_ant\nossoken\testeBuild.xml
[echo] Teste com o FOR
[echo] C:\temp\Empresa.java
[echo] C:\temp\Empresa1.java
[echo] C:\temp\Empresa2.java
[echo] C:\temp\Empresa3.java
main:
BUILD SUCCESSFUL
Total time: 797 milliseconds
Eu preciso que a saída seja a seguinte:
Buildfile: D:\Desenv\workspace_ant\nossoken\testeBuild.xml
[echo] Teste com o FOR
[echo] Empresa
[echo] Empresa1
[echo] Empresa2
[echo] Empresa3
main:
BUILD SUCCESSFUL
Total time: 797 milliseconds
Alguém tem idéia de como fazer isso?
Pessoal estou tentando criar uma arquivo “application.xml” para compilação de um “ear”, estou usando “Ant-Contrib”, alguem pode dar uma ajuda??
Agradeço
Caraca,
to precisando fazer isso no ANT, nunca precisei disso e agora não sei qual é a propriedade que imprime só o nome do arquivo sem o caminho absoluto!
Buildfile: D:\Desenv\workspace_ant\nossoken\testeBuild.xml
[echo] Teste com o FOR
[echo] Empresa
[echo] Empresa1
[echo] Empresa2
[echo] Empresa3
main:
BUILD SUCCESSFUL
Total time: 797 milliseconds
Alguém manja?
Você pode criar a sua própria task.
http://ant.apache.org/manual/develop.html
Abraço,
Fred
[quote=felipeguerra]Caraca,
to precisando fazer isso no ANT, nunca precisei disso e agora não sei qual é a propriedade que imprime só o nome do arquivo sem o caminho absoluto!
Buildfile: D:\Desenv\workspace_ant\nossoken\testeBuild.xml
[echo] Teste com o FOR
[echo] Empresa
[echo] Empresa1
[echo] Empresa2
[echo] Empresa3
main:
BUILD SUCCESSFUL
Total time: 797 milliseconds
Alguém manja?[/quote]
Infelizmente, não posso utilizar meu tempo para criar uma task, se já não tem pronto, vou para um plano B.
Valeu!