我正在尝试将Maven站点部署到FTP服务器。我在我的pom.xml中使用了以下代码:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>ftp</id>
<phase>post-site</phase>
<configuration>
<tasks>
<ftp action="del" server="nexus"
remotedir="/pub/${project.groupId}/${project.artifactId}"
userid="anonymous" password="my.name@gmail.com"
skipFailedTransfers="true" ignoreNoncriticalErrors="true">
<fileset>
<include name="**/" />
</fileset>
</ftp>
<ftp action="rmdir" server="nexus"
remotedir="/pub/${project.groupId}/${project.artifactId}"
userid="anonymous" password="my.name@gmail.com"
skipFailedTransfers="true" ignoreNoncriticalErrors="true">
<fileset>
<include name="**/" />
</fileset>
</ftp>
<ftp action="mkdir" server="nexus"
remotedir="/pub/${project.groupId}/${project.artifactId}"
userid="anonymous" password="my.name@gmail.com" depends="yes"
verbose="no" chmod="777">
</ftp>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>在这里,我删除了以前部署的站点,并在站点后期阶段为该站点创建了一个新目录,以便部署将具有所需的结构。问题是它第一次不起作用--当要删除的文件夹不存在的时候。在第一次,我必须手动创建目录,这样它才能工作。在第一次之后,它工作得很好。
我的问题是,在尝试删除目录之前,如何检查该目录是否存在。
谢谢,罗南。
发布于 2009-08-10 15:15:46
您可以在调用ftp del任务之前先执行ftp mkdir,这样可以确保在删除该目录之前该目录已经存在。当然,如果该目录已经存在,则可能会失败。我无法测试这一点,但根据docs,如果目录存在,添加ignoreNoncriticalErrors="true“可能会让mkdir不会失败。
例如:
<ftp action="mkdir"
server="nexus"
userid="anonymous"
password="my.name@gmail.com"
remotedir="/pub/${project.groupId}/${project.artifactId}"
ignoreNoncriticalErrors="true"/>更新:从Ftp.java上看,这看起来是可行的:
/**
* Create the specified directory on the remote host.
*
* @param ftp The FTP client connection
* @param dir The directory to create (format must be correct for host
* type)
* @throws IOException in unknown circumstances
* @throws BuildException if ignoreNoncriticalErrors has not been set to true
* and a directory could not be created, for instance because it was
* already existing. Precisely, the codes 521, 550 and 553 will trigger
* a BuildException
*/
protected void makeRemoteDir(FTPClient ftp, String dir)
throws IOException, BuildException {
...https://stackoverflow.com/questions/1255414
复制相似问题