如果文件可用,则Ant找不到文件作为属性

时间:2015-06-04 09:10:48

标签: maven ant

我在Maven中使用以下Ant代码

<properties>
    <uninstaller.filename>MyName</uninstaller.filename>
    ....
</properties>
<if>
    <available file="${project.build.directory}/${uninstaller.filename}"/>
    <then>
        <echo> Run Commands.... </echo>                             
        <echo> [INFO]   Done! </echo>
        <echo> [INFO]   Running un-installation...</echo>
        <exec dir="${project.build.directory}"           executable="${project.build.directory}/${uninstaller.filename}**" failonerror="false">
     </exec>
    <echo> [INFO]   My progrm was uninstalled successfully!</echo>
 </then>
<else>
    <echo>[INFO]    No previous program found...</echo>
</else>
</if>

代码找不到我的卸载程序(名称只是MyName而不是MyName。*)但是当我写它时#34;硬编码&#34; -

<available file="${project.build.directory}/MyName"/>

确实有效...... 我检查它是否相同,文件是否存在。 该物业也有明确的定义 任何的想法?这是可用吗?

感谢

1 个答案:

答案 0 :(得分:0)

您无需在属性中指定project

试试此文件mvn install

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>test</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>test</name>
    <url>http://maven.apache.org</url>

    <properties>
        <dir.name>./</dir.name>
        <uninstaller.filename>pom.xml</uninstaller.filename>
    </properties>

    <!-- Build Configuration -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.7</version>
                <dependencies>
                    <dependency>
                        <groupId>ant-contrib</groupId>
                        <artifactId>ant-contrib</artifactId>
                        <version>20020829</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>initialize</id>
                        <phase>initialize</phase>
                        <configuration>
                            <tasks>
                                <taskdef resource="net/sf/antcontrib/antcontrib.properties" />

                                <echo message="${dir.name}"/>
                                <echo message="${uninstaller.filename}"/>
                                <if>
                                    <available file="${dir.name}/${uninstaller.filename}"/>
                                    <then>
                                        <echo>!!!!!!!!!!!!!!! OK </echo>
                                    </then>
                                    <else>
                                        <echo>!!!!!!!!!!!!!!!! NOT FOUND</echo>
                                    </else>
                                </if>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>