我相信我正确设置了所有内容,但是在运行调用ANT Migration可执行文件的Powershell脚本时出现以下错误:
At C:\Users\user\Desktop\backup_script.ps1:13 char:1
+ &ant "retrieveObjects"
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError BUILD FAILED C:\Users\user\Desktop\AntCode\ant-salesforce-prgm\build.xml:63: Problem: failed to create task or type antlib:com.salesforce:retrieve 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:
-C:\apache-ant-1.10.2\lib
-C:\Users\user\.ant\lib
-a directory added on the command line with the -lib argument Total time: 0 seconds
这是我的build.xml文件:
<project name="Sample usage of Salesforce Ant tasks" default="test" basedir="." xmlns:sf="antlib:com.salesforce">
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property file="build.properties"/>
<property environment="env"/>
<!-- Setting default value for username, password and session id properties to empty string
so unset values are treated as empty. Without this, ant expressions such as ${sf.username}
will be treated literally.
-->
<macrodef name="export">
<attribute name="file"/>
<attribute name="object"/>
<attribute name="soql"/>
<attribute name="userName"/>
<attribute name="password"/>
<attribute name="serverURL"/>
<attribute name="batchSize"/>
<attribute name="limit"/>
<sequential>
<echo message="Exporting @{object}"/>
<mkdir dir="exports/DATE"/>
<mkdir dir="logs/DATE"/>
<copy file="config/template-process-conf.xml" tofile="config/process-conf.xml" overwrite="true" failonerror="true"/>
<replace file="config/process-conf.xml">
<replacefilter token="_object_" value="@{object}"/>
<replacefilter token="_soql_" value="@{soql}"/>
<replacefilter token="_file_" value="exports/${todayDate_only}/@{file}.csv"/>
<replacefilter token="_serverURL_" value="@{serverURL}"/>
<replacefilter token="_userName_" value="@{username}"/>
<replacefilter token="_password_" value="@{password}"/>
<replacefilter token="_batchSize_" value="@{batchSize}"/>
<replacefilter token="_logFile_" value="logs/DATE/@{file}_log.csv"/>
</replace>
<java classname="com.salesforce.dataloader.process.ProcessRunner" classpath="C:\YOUR_PATH\dataloader-39.0.0-uber.jar" failonerror="true">
<sysproperty key="salesforce.config.dir" value="config"/>
<arg line="process.name=@{object}"/>
</java>
</sequential>
</macrodef>
<!--
<condition property="sf.username" value=""> <not> <isset property="sf.username"/> </not> </condition>
<condition property="sf.password" value=""> <not> <isset property="sf.password"/> </not> </condition>
<condition property="sf.sessionId" value=""> <not> <isset property="sf.sessionId"/> </not> </condition>
<taskdef resource="com/salesforce/antlib.xml" uri="antlib:com.salesforce">
<classpath>
<pathelement location="ant-salesforce.jar" />
</classpath>
</taskdef>
-->
<!-- See what happens here -->
<target name="retrieveObjects">
<mkdir dir="retrieveObjects"/>
<sf:retrieve
username="${sf.prod.profileName.username}"
password="${sf.prod.profileName.password}"
sessionId="${sfProd.sessionId}"
serverurl="${sfProd.serverurl}"
retrieveTarget="retrieveObjects"
unpackaged="retrieveSource/package.xml"/>
</target>
<target name="foo">
<foreach target="backup" param="file">
<path>
<fileset dir="YOUR_PATH_objects" includes="**/*.object"/>
</path>
</foreach>
</target>
<target name="backup">
<xmlproperty file="retrieveObjects/objects/Account.object" collapseAttributes="true"/> <!--this parses the xml file-->
<export
file="Account_backup-DATE"
object="Account"
soql="select ${CustomObject.fields.fullName} from Account"
userName="${sf.prod.profileName.username}"
password="${sf.prod.profileName.password}"
serverURL="${sfProd.serverurl}"
batchSize="200"
limit = "1000" />
</target>
</project>
我不确定问题出在哪里。我将ant-contrib-1.0b3.jar文件放入以下目录: C:\ apache-ant-1.10.2 \ lib ,但似乎没有解决它。
答案 0 :(得分:0)
这取决于你的蚂蚁版本。 您的ant-contrib文件可能与您正在运行的ant版本不兼容。
我有一个类似的错误,它通过使用ant-contrib-1.0b1.jar来解决。下载ant-contrib-1.0b1-bin.zip并解压缩以查找其中的.jar文件。
我正在运行的ant版本是1.10.3
您也可以尝试将其添加到build.xml文件中:
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
希望这有帮助!