首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用FTP Ant任务部署Maven站点

问使用FTP Ant任务部署Maven站点
EN

Stack Overflow用户
提问于 2009-08-10 15:00:54
回答 1查看 2K关注 0票数 2

我正在尝试将Maven站点部署到FTP服务器。我在我的pom.xml中使用了以下代码:

代码语言:javascript
复制
<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>

在这里,我删除了以前部署的站点,并在站点后期阶段为该站点创建了一个新目录,以便部署将具有所需的结构。问题是它第一次不起作用--当要删除的文件夹不存在的时候。在第一次,我必须手动创建目录,这样它才能工作。在第一次之后,它工作得很好。

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

谢谢,罗南。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2009-08-10 15:15:46

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

例如:

代码语言:javascript
复制
<ftp action="mkdir"
  server="nexus"
  userid="anonymous"
  password="my.name@gmail.com"
  remotedir="/pub/${project.groupId}/${project.artifactId}"
  ignoreNoncriticalErrors="true"/>

更新:从Ftp.java上看,这看起来是可行的:

代码语言:javascript
复制
/**
 * 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 {
    ...
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1255414

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档