在参考了这篇文章和这篇文章之后,我尝试从java类运行ant脚本,如下所示:
File buildFile = new File("D:\Utility\artifacts\build.xml");
Project p = new Project();
p.setUserProperty("ant.file", buildFile.getAbsolutePath());
DefaultLogger consoleLogger = new DefaultLogger();
consoleLogger.setErrorPrintStream(System.err);
consoleLogger.setOutputPrintStream(System.out);
consoleLogger.setMessageOutputLevel(Project.MSG_INFO);
p.addBuildListener(consoleLogger);
try
{
p.fireBuildStarted();
p.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
p.addReference("ant.projectHelper", helper);
helper.parse(p, buildFile);
p.executeTarget(p.getDefaultTarget());
p.fireBuildFinished(null);
}
catch (BuildException e)
{
p.fireBuildFinished(e);
}
以下是构建.xml文件:
<project name="buildWebservice" default="generate-from-wsdlc">
<taskdef name="wsdlc" classname="weblogic.wsee.tools.anttasks.WsdlcTask"
classpath="D:beawlserver_10.3serverlibweblogic.jar" />
<target name="generate-from-wsdlc">
<wsdlc srcWsdl="D:UtilityWSDLssomeWSDL.wsdl"
type="JAXWS" destJwsDir="tempJWS_InterfaceDir" destImplDir="tempJWS_ImplDir">
</wsdlc>
</target>
</project>
但是当我执行此 java 代码时,我在控制台中收到以下异常:
BUILD FAILED
D:Utilityartifactsbuild.xml:21: java.lang.NoSuchMethodError: com.sun.xml.ws.util.JAXWSUtils.getEncodedURL(Ljava/lang/String;)Ljava/net/URL;
我甚至反编译了jaxws-rt.jar以在JAXWSUtils类中查找getEncodedURL方法,但没有找到任何这样的方法。
请帮忙!提前致谢
尝试与此论坛条目不同的实现:https://forums.oracle.com/forums/thread.jspa?threadID=1125462