Java 如何防止Maven在Ant任务失败时构建失败?
我用的是 但是这些都不能解决问题,构建也会不断失败。Java 如何防止Maven在Ant任务失败时构建失败?,java,ant,ftp,maven-2,maven-antrun-plugin,Java,Ant,Ftp,Maven 2,Maven Antrun Plugin,我用的是 但是这些都不能解决问题,构建也会不断失败。 An Ant BuildException has occured: could not change remote directory: 550 /myBadDir: The system cannot find the file specified. 您知道如何指示我的maven构建不关心这个Ant任务错误/或者如何指示Ant在缺少目录的情况下不失败吗 编辑: 彼得的解决方案有效。 如果你遇到这样的问题 [INFO] Error con
An Ant BuildException has occured: could not change remote directory: 550 /myBadDir: The system cannot find the file specified.
您知道如何指示我的maven构建不关心这个Ant任务错误/或者如何指示Ant在缺少目录的情况下不失败吗
编辑:彼得的解决方案有效。
如果你遇到这样的问题
[INFO] Error configuring: org.apache.maven.plugins:maven-antrun-plugin. Reason: java.lang.NoSuchMethodError: org.apache.tools.ant.util.FileUtils.close(Ljava/io/InputStream;)V
只需将ant排除在ant contrib之外
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>${ant-contrib.ver}</version>
<exclusions>
<exclusion>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
</exclusion>
</exclusions>
</dependency>
抗辩人
抗辩人
${antcontrib.ver}
蚂蚁
蚂蚁
在这种情况下,您可能需要多想一想,少想一想
这里有一个解决方案。使用任务。下面是一个pom.xml示例。将代码块复制到名为pom.xml
的文件中,然后运行mvn validate
以查看其工作情况
<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>com.stackoverflow.q2666794</groupId>
<artifactId>trycatch</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>trycatch</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>trycatch</id>
<phase>validate</phase>
<configuration>
<tasks>
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
<trycatch>
<try>
<fail>Failing ftp task should go here</fail>
</try>
<catch>
<echo>See the error was caught and ignored</echo>
</catch>
</trycatch>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>1.0b3</version>
<exclusions>
<exclusion>
<artifactId>ant</artifactId>
<groupId>ant</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
4.0.0
com.stackoverflow.q2666794
trycatch
罐子
1.0-快照
trycatch
http://maven.apache.org
org.apache.maven.plugins
maven antrun插件
1.3
trycatch
验证
失败的ftp任务应转到此处
请参阅错误被捕获并忽略
跑
抗辩人
抗辩人
1.0b3
蚂蚁
蚂蚁
自maven antrun plugin 1.7以来,您可以在配置中添加标签FailOneError
org.apache.maven.plugins
maven antrun插件
ftp
产生资源
假的
跑
我不知道如何跳过这个错误,但是为什么在Maven的生成资源阶段使用antcall呢。可能是部署阶段的一部分,也许你可以解释一下,在运行测试之前,我只需要更新项目的资源。实际上,Ant任务应该在“生成测试资源”阶段运行。资源(部署时不需要)由测试类使用。如果ftp文件夹不存在,我不希望ant任务失败。
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>${ant-contrib.ver}</version>
<exclusions>
<exclusion>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
</exclusion>
</exclusions>
</dependency>
<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>com.stackoverflow.q2666794</groupId>
<artifactId>trycatch</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>trycatch</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>trycatch</id>
<phase>validate</phase>
<configuration>
<tasks>
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
<trycatch>
<try>
<fail>Failing ftp task should go here</fail>
</try>
<catch>
<echo>See the error was caught and ignored</echo>
</catch>
</trycatch>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>1.0b3</version>
<exclusions>
<exclusion>
<artifactId>ant</artifactId>
<groupId>ant</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>