Ant WsImport2因java.lang.NoClassDefFoundError而失败:

时间:2019-01-30 10:58:47

标签: java ant wsdl wsdl2java wsimport

我已经这样定义了我的Ant脚本:

<taskdef name="xjc" classname="com.sun.tools.xjc.XJC2Task">
    <classpath>
        <path refid="extraJars" />
    </classpath> 
</taskdef>

<taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport2">
    <classpath>
        <path refid="extraJars" />
    </classpath>
</taskdef>

在“ extraJars”中,我具有运行任务所需的所有Jar。喜欢:

jaxb-api-2.3.1.jar
jaxb-impl-2.2.6.jar
jaxb-xjc-2.2.7.jar
jaxws-tools-2.3.2.jar

现在,当我运行脚本时,出现错误:

H:\Workspace\common-build.xml:740: java.lang.NoClassDefFoundError: com/sun/istack/localization/LocalizableMessageFactory$ResourceBundleSupplier
        at com.sun.tools.ws.wscompile.WsimportTool$1AuthListener.onError(WsimportTool.java:377)
        at com.sun.istack.tools.DefaultAuthenticator.setAuth(DefaultAuthenticator.java:138)
        at com.sun.tools.ws.wscompile.WsimportTool.buildWsdlModel(WsimportTool.java:400)
        at com.sun.tools.ws.wscompile.WsimportTool.run(WsimportTool.java:175)
        at com.sun.tools.ws.wscompile.WsimportTool.run(WsimportTool.java:153)
        at com.sun.tools.ws.ant.WsImportBase.runInVm(WsImportBase.java:569)
        at com.sun.tools.ws.ant.WsTask2.execute(WsTask2.java:457)
        at com.sun.tools.ws.ant.WsImportBase.execute(WsImportBase.java:552)
        at com.sun.tools.ws.ant.WsImport2.execute(WsImport2.java:23)
        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:1388)
        at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:36)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
        at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:437)
        at org.apache.tools.ant.taskdefs.SubAnt.execute(SubAnt.java:306)
        at org.apache.tools.ant.taskdefs.SubAnt.execute(SubAnt.java:225)
        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:1388)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1361)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
        at org.apache.tools.ant.Main.runBuild(Main.java:834)
        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)
Caused by: java.lang.ClassNotFoundException: com.sun.istack.localization.LocalizableMessageFactory$ResourceBundleSupplier
        at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1362)
        at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1313)
        at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1068)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 39 more

Total time: 11 seconds

我做了一些谷歌,我看到com / sun / istack / localization / LocalizableMessageFactory $ ResourceBundleSupplier类存在于我所包含的jaxb-Impl jar中。我检查了Java2s网站。您能告诉我哪里出了问题吗?还是我需要一些额外的JARS?

只需添加一下构建文件中的第740行:

 <wsimport wsdl="${build.dir}/src/${wsdl.file}" destdir="build" wsdlLocation="file:/WEB-INF/wsdl/${wsdl.file}" failonerror="true">
        <depends dir="${build.dir}/src" includes="*.xsd" /> 
        <produces dir="${lib.dir}" includes="${webservice.name}${webservice.component}WSBeans.jar"/>
    </wsimport>

1 个答案:

答案 0 :(得分:0)

我用JAXB Core Jar的更新版本进行了修复。

缺少的课程在:

jaxb-core-2.3.0.1.jar

以前,我在使用:

jaxb-core-2.2.7.jar