ANT错误:无法创建任务或键入antlib:com.salesforce:deploy

时间:2013-02-12 14:57:38

标签: ant salesforce force.com

我开始使用Force.com Migration Tool。我想从ANT构建文件中使用它。我创造了这个:

<project name="Subversion to Org" default="deploy" basedir="." xmlns:sf="antlib:com.salesforce">
    <target name="deploy">
        <echo message="deploying from metadata" />
        <echo message="ANT_HOME=${ant.home}"/>
        <echo message="BASEDIR=${basedir}"/>
        <echo message="ANT_CORE_LIB=${ant.core.lib}"/>
        <echo message="JAVA_VERSION=${ant.java.version}"/>
        <echo message="ANT_LIBRARY_DIR=${ant.library.dir}"/>
        <echo message="classpath=${java.class.path}"/>
        <sf:deploy username="${properties.username}"
                        password="${properties.password}"
                        serverurl="${properties.url}"
                        deployroot="${properties.root}"
                        singlePackage="${properties.singlePackage}"
                        runAllTests="${properties.allTest}" />
        </target>
</project>

我在ant.lib文件夹中复制了ant-salesforce.jar。当我通过ANT执行此文件时,我得到了这个:

     Buildfile: build.xml

deploy:
     [echo] deploying from metadata
     [echo] ANT_HOME=/usr/share/ant
     [echo] BASEDIR=/usr/share/tomcat6/.jenkins/jobs/Salesforce Deploy Test/workspace/deploy script
     [echo] ANT_CORE_LIB=/usr/share/java/ant-1.7.1.jar
     [echo] JAVA_VERSION=1.6
     [echo] ANT_LIBRARY_DIR=/usr/share/ant/lib
     [echo] classpath=/usr/share/java/ant.jar:/usr/share/java/ant-launcher.jar:/usr/share/java/jaxp_parser_impl.jar:/usr/share/java/xml-commons-apis.jar:/usr/lib/jvm/java/lib/tools.jar:/usr/share/ant/lib/ant.jar:/usr/share/ant/lib/ant-launcher.jar:/usr/share/ant/lib/ant-salesforce.jar:/usr/share/ant/lib/ant-bootstrap.jar

BUILD FAILED
/usr/share/tomcat6/.jenkins/jobs/Salesforce Deploy Test/workspace/deploy script/build.xml:16: Problem: failed to create task or type antlib:com.salesforce:deploy
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
No types or tasks have been defined in this namespace yet

This appears to be an antlib declaration.
Action: Check that the implementing library exists in one of:
        -/usr/share/ant/lib
        -/root/.ant/lib
        -a directory added on the command line with the -lib argument


Total time: 0 seconds

似乎找不到ant-salesforce.jar文件,但它出现在输出中。有什么想法吗?

更多信息:

权限检查

ls -al /usr/share/ant/lib
total 3412
drwxr-xr-x. 2 root root    4096 feb 12 15:36 .
drwxr-xr-x. 4 root root    4096 feb 12 09:49 ..
lrwxrwxrwx. 1 root root      28 feb 12 09:49 ant-bootstrap.jar -> ../../java/ant-bootstrap.jar
lrwxrwxrwx. 1 root root      18 feb 12 09:49 ant.jar -> ../../java/ant.jar
lrwxrwxrwx. 1 root root      27 feb 12 09:49 ant-launcher.jar -> ../../java/ant-launcher.jar
-rwxrwxrwx. 1 root root 3483648 feb 12 12:58 ant-salesforce.jar

Jar内容检查:

...
com/salesforce/ant/BulkRetrieveTask.class
com/salesforce/ant/CompileAndTest$CodeNameElement.class
com/salesforce/ant/CompileAndTest$RunTestsElement.class
com/salesforce/ant/CompileAndTest.class
com/salesforce/ant/Configuration.class
com/salesforce/ant/ConnectionFactory.class
com/salesforce/ant/DeployTask$CodeNameElement.class
com/salesforce/ant/DeployTask.class
com/salesforce/ant/DescribeMetadataTask.class
com/salesforce/ant/ListMetadataTask.class
com/salesforce/ant/RetrieveTask$PackageManifestParser.class
com/salesforce/ant/RetrieveTask.class
com/salesforce/ant/SFDCAntTask.class
com/salesforce/ant/SFDCMDAPIAntTask.class
com/salesforce/ant/SFDCMDAPIAntTaskRunner.class
com/salesforce/ant/ZipUtil.class
com/salesforce/antlib.xml
...

antlib文件内容(按预期方式):

<antlib>
    <typedef name="compileAndTest" classname="com.salesforce.ant.CompileAndTest"/>
    <typedef name="deploy" classname="com.salesforce.ant.DeployTask"/>
    <typedef name="retrieve" classname="com.salesforce.ant.RetrieveTask"/>
    <typedef name="bulkRetrieve" classname="com.salesforce.ant.BulkRetrieveTask"/>
    <typedef name="listMetadata" classname="com.salesforce.ant.ListMetadataTask"/>
    <typedef name="describeMetadata" classname="com.salesforce.ant.DescribeMetadataTask"/>
</antlib>

提前致谢。

3 个答案:

答案 0 :(得分:1)

您的sf:deploy语法很好。匹配我的。

检查您的项目定义。您是否将xmlns:sf的命名空间设置为正确的值?

应该是:

<project name="salesforce" default="deploy" basedir="." xmlns:sf="antlib:com.salesforce">

您还可以检查ant-salesforce.jar的权限。

然后检查jar是否已损坏

jar -tf ant-salesforce.jar

答案 1 :(得分:0)

已解决:我重新安装了蚂蚁,现在一切似乎都运行正常。奇怪的是。

感谢您的支持人员

答案 2 :(得分:0)

我遇到了同样的问题,通过更改ant-salesforce.jar lib的权限来修复它。

对于遇到此问题的人来说,如果lib上没有权限问题,则值得检查。