简体   繁体   English

如何在ftp任务的构建文件中指定类路径

[英]How can I specify the classpath in the build file of an ftp tasks

I would like to specify the classpath for an fpt task directly in my Ant Build script. 我想直接在我的Ant Build脚本中指定fpt任务的类路径。 I tried the following: 我尝试了以下方法:

<target name="ftp-upload" depends="build-html">     
   <echo message="Ftp upload started with user ${user}" />
<ftp verbose="yes" 
            remotedir="${ftp.dir}" 
    server="${server}"
            userid="${user}" 
    password="${password}" 
    depends="yes">
      <fileset dir="${mystuff.dir}/.." />
     <classpath refid="build.classpath" />
</ftp>
</target>

and

<target name="ftp-upload" depends="build-html">     
 <echo message="Ftp upload started with user ${user}" />
<ftp verbose="yes" 
            remotedir="${ftp.dir}" 
    server="${server}"
            userid="${user}" 
    password="${password}" 
    depends="yes"
            classpathref="build.classpath"
     >
      <fileset dir="${mystuff.dir}/.." />
</ftp>
</target>

The first approach gives me the following error message: 第一种方法给我以下错误消息:

Could not create type ftp due to java.lang.NoClassDefFoundError:      org/apache/commons/net/ftp/FTPClientConfig

The second approach gives me the following error message: 第二种方法给我以下错误消息:

ftp doesn't support the "classpathref" attribute

Is it possible to set the classpath in the build script for the ftp tasks or do I have to do it outside the build script on my server? 是否可以在构建脚本中为ftp任务设置类路径,还是必须在我的服务器上的构建脚本之外进行? Would be nice to have the build script self-contained. 将构建脚本自包含会很高兴。

Solution: 解:

Just re-define the ftp task with your classpath reference: 只需使用类路径引用重新定义ftp任务:

<taskdef name="ftp" classname="org.apache.tools.ant.taskdefs.optional.net.FTP">
 <classpath>
    <pathelement location="\lib\commons-net-1.4.0.jar"/>
 </classpath>
</taskdef>

Have you tried the solution commented at How to load an optional task into ant without -lib or global installation? 您是否尝试过如何在没有-lib或全局安装的情况下将可选任务加载到ant中的解决方案 ?

I had a similar problem some time ago and I solved it adding a new classloader. 我前段时间遇到了类似的问题,我解决了它添加一个新的类加载器。

Regards 问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Objective-C如何将文件上传到FTP服务器? (简单) - Objective-C How can I upload a file to FTP server? (Simple) 我如何使用已使用N周的Java程序从ftp服务器中删除文件 - How can I delete a file from an ftp server using a java program that are N weeks old 如何在没有硬编码绝对路径的情况下在.htaccess文件中指定auto_prepend_file? - How can I specify an auto_prepend_file in my .htaccess file without hardcoding the absolute path? 如何在类路径中链接DLL文件 - How to link DLL file in classpath 我可以指定用户名和密码来通过HTTP访问文件吗? - Can I specify a username and password to access a file over HTTP? 如何在Apache服务器上为用户创建只读FTP访问? - How can I create read-only FTP access for user on Apache server? 如何在通过ftp更新时自动将暂停模式设置为我的站点 - how can I set suspend mode automatically to my site while updating via ftp 如何设置EC2所有权权限,以允许我通过FTP更新WordPress和修改文件? - How can I set EC2 ownership permissions that allow me to update WordPress and modify files via FTP? 如果URL未指定文件,如何使我的网站加载特定文件? - How do I make my website load a specific file when the URL doesn't specify the file? 黑客可以入侵网站的FTP,SSH和/或.htaccess文件吗? - Can a hacker hack a website's FTP, SSH and/or .htaccess file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM