使用FTP Ant任务部署Maven站点 [英] Deploy Maven site using FTP Ant task

查看:125
本文介绍了使用FTP Ant任务部署Maven站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想部署一个Maven站点到FTP服务器。我使用下面的code在我的pom.xml:

I am trying to deploy a Maven site to an FTP server. I am using the following code in my 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>

下面我删除部署了previous网站,并创造了现场后阶段网站一个新的目录,以便部署将拥有它所需要的结构。
的问题是,它不是第一次工作 - 当夹删除不存在。在我第一次必须手动创建目录,以便将工作。
第一次后,效果很好。

Here I delete the previous site deployed, and creating a new directory for the site in the post-site phase, so that the deploy will have the structure it needs. The problem is that it doesn't work for the first time - when folder to delete does not exist. In the first time I must manually create the directory so it will work. after the first time it works well.

我的问题是我怎么想删除它之前检查目录是否存在。

my question is how do I check the existence of the directory before trying to delete it.

谢谢,
罗南。

Thanks, Ronen.

推荐答案

您可以做的 FTP的mkdir 首先在 FTP德尔任务调用之前,这将确保目录删除之前存在。但当然,如果该目录已存在可能会失败。我不能对此进行测试,但根据文档,加入 ignoreNoncriticalErrors =真正的的可能会让如果目录中的mkdir不会失败。

You could do ftp mkdir first before the ftp del task is called, this would ensure the directory exists before deleting it. though of course that might fail if the directory already exists. I'm not able to test this, but according to the docs, adding ignoreNoncriticalErrors="true" might let mkdir not fail if the directory exists.

例如:

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

更新:从<一个href=\"http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java?annotate=739572&pathrev=739572\"相对=nofollow> Ftp.java 的它看起来像这样将工作:

Update: From Ftp.java it looks like this will work:

/**
 * 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 {
    ...

这篇关于使用FTP Ant任务部署Maven站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆