java.lang.ClassNotFoundException: com.salesforce.ant.DeployT



我正在build.xml 中执行目标

<target name="validateProd">
<echo>[18] Validation Begins...</echo>
<if>
<and><equals arg1="${canDeploy}" arg2="true"/> </and>
<then>
<fail message="Test Class Not Specified" unless="env.testClass"/>
<echo>[19] ${env.testClass}</echo>
<script language="javascript"><![CDATA[
var deployTask = project.createTask('antlib:com.salesforce:deploy');
deployTask.setUsername(project.getProperty("sf.username"));
deployTask.setPassword(project.getProperty("sf.password"));
deployTask.setServerURL(project.getProperty("sf.serverurl"));
deployTask.setDeployRoot(project.getProperty("sf.deployDir"));
deployTask.setCheckonly(true);
deployTask.setTestLevel('RunSpecifiedTests');
deployTask.setMaxPoll(project.getProperty("sf.maxPoll"));
var tests = project.getProperty("env.testClass");
if (tests) {
deployTask.setTestLevel('RunSpecifiedTests');
tests = tests.split(',');
for (var i = 0; i < tests.length; i++) {
var runTest = java.lang.Class.forName(
"com.salesforce.ant.DeployTask$CodeNameElement"
).newInstance();
runTest.addText(tests[i]);
deployTask.addRunTest(runTest);
}
deployTask.perform();
}
]]></script>
</then>
<else>
<echo>[20] Nothing to deploy</echo>
</else>
</if>
</target>

我得到以下异常:

BUILD FAILED

D:ar1a_sfdcautobuild.xml:376: java.lang.ClassNotFoundException: com.salesforce.ant.DeployTask$
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at jdk.nashorn.internal.runtime.ScriptLoader.findClass(ScriptLoader.java:83)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at jdk.nashorn.internal.runtime.ScriptLoader.loadClass(ScriptLoader.java:55)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at java.lang.invoke.MethodHandleImpl$BindCaller$T/1873091796.invoke_V(MethodHandleImpl.java:1258)
at jdk.nashorn.internal.scripts.Script$^eval_.:program(<eval>:13)
at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:637)
at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494)
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:449)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:406)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:402)
at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:155)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
at org.apache.tools.ant.util.optional.JavaxScriptRunner.evaluateScript(JavaxScriptRunner.java:154)
at org.apache.tools.ant.util.optional.JavaxScriptRunner.executeScript(JavaxScriptRunner.java:86)
at org.apache.tools.ant.taskdefs.optional.Script.execute(Script.java:53)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
at org.apache.tools.ant.Task.perform(Task.java:350)
at java.util.Vector.forEach(Vector.java:1277)
at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:67)
at net.sf.antcontrib.logic.IfTask.execute(IfTask.java:197)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
at org.apache.tools.ant.TaskAdapter.execute(TaskAdapter.java:155)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
at org.apache.tools.ant.Task.perform(Task.java:350)
at org.apache.tools.ant.Target.execute(Target.java:449)
at org.apache.tools.ant.Target.performTasks(Target.java:470)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1401)
at org.apache.tools.ant.Project.executeTarget(Project.java:1374)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1264)
at org.apache.tools.ant.Main.runBuild(Main.java:827)
at org.apache.tools.ant.Main.startAnt(Main.java:223)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:284)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:101)

我已经在build.xml中有了以下内容:

<taskdef resource="com/salesforce/antlib.xml" uri="antlib:com.salesforce">
<classpath>
<pathelement location="lib/ant-salesforce.jar"/>
</classpath>
</taskdef>
  • 我可以通过在我的个人机器,并通过将ant-salesforce.jar添加到ant_HOME/lib文件夹
  • 在Azure devops上,我还尝试通过shell/cmd任务将文件复制到在执行ANT任务之前,azure devops中的ANT_HOME/lib,但我不是能够解决此异常
  • 我还尝试了在选项中使用lib,例如本问题中提到的ant deploy -Ddir=src -Dtests=Class1,Class2,Class3 -lib ant-salesforce.jar

有什么方法可以将ant-salesforce.jar添加到ant_HOME/lib的lib中吗或正确引用antlib.com.salesforce:deploy

Microsoft托管代理由Microsoft维护,如果您希望对安装构建和部署所需的依赖软件有更多的控制权,则需要部署自托管代理并在Azure管道中使用它。请检查一下,并告诉我结果。

SSJOY提供了解决方案,可以通过在yml中添加vmImage:windows最新版本来解决此问题,因此此管道将在Visual Studio 2019中使用image:windows Server 2019。

在这里发帖,这样其他有同样问题的人可以很快找到它。感谢SSJOY的分享。

相关内容

  • 没有找到相关文章

最新更新