Maven 2 使用FTP Ant任务部署Maven站点

Maven 2 使用FTP Ant任务部署Maven站点,maven-2,ant,ftp,deployment,Maven 2,Ant,Ftp,Deployment,我正在尝试将Maven站点部署到FTP服务器。我在pom.xml中使用以下代码: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <id>ftp</id> &l

我正在尝试将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>

org.apache.maven.plugins
maven antrun插件
ftp
驿站
跑
在这里,我删除了以前部署的站点,并在站点发布阶段为站点创建了一个新目录,以便部署具有所需的结构。 问题是,当要删除的文件夹不存在时,它第一次就不起作用了。第一次,我必须手动创建目录,这样它才能工作。 第一次之后,它工作得很好

我的问题是,在尝试删除目录之前,如何检查目录是否存在

谢谢,
罗南

您可以在调用ftp del任务之前先执行ftp mkdir,这将确保在删除目录之前该目录存在。当然,如果目录已经存在,那么这可能会失败。我无法测试这一点,但根据,如果目录存在,添加ignoreNoncriticalErrors=“true”可能会使mkdir不会失败

例如:

<ftp action="mkdir"
  server="nexus"
  userid="anonymous"
  password="my.name@gmail.com"
  remotedir="/pub/${project.groupId}/${project.artifactId}"
  ignoreNoncriticalErrors="true"/>

非常感谢,你是对的。“del”和“rmdir”操作是冗余的,现在它只适用于“mkdir”操作。它只是不删除以前的版本,只是覆盖它-这是我可以接受的。谢谢
/**
 * 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 {
    ...