从 Java 中的 wsdl 生成 Web 服务存根

发布于 2024-09-07 13:14:23 字数 1870 浏览 5 评论 0原文

我正在开发 eclipse 插件,它将有一个向导。当鼠标右键单击 Java 编辑器时,可以从上下文菜单中使用该向导的示例。

该向导将负责收集以下信息:

  • WSDL 文件的位置
  • 包名称

当向导完成时,我希望将 WSDL 中描述的 Web 服务存根生成到之前提供的包中。

问题是:如何从源代码(而不是从命令行)动态生成 W​​eb 服务存根并将其添加到当前项目中?

到目前为止,我接触过 WSDL2Java (Axis)、Apache CXF 和 wsimport。我尝试使用 Apache CXF 和 wsimport,但即使所有 jar 都包含在构建路径中,我总是收到 ClassNotFoundException。我想我可能错误地使用了它们。

请大家帮助我!该任务的时间已经不多了:-(

小例子:

假设代码是 (Apache CXF):

String[] args = {"-client", "-d", "D:\\test", "D:\test.wsdl" };
WSDLToJava w = new WSDLToJava(args);
ToolContext t = new ToolContext();
w.run(t);

异常的前几行是:

java.lang.NoClassDefFoundError: org/apache/cxf/tools/wsdlto/WSDLToJava
    at plugin.wsreplication.ui.wizard.component.AddComponentWizard.performFinish(AddComponentWizard.java:160)
    at org.eclipse.jface.wizard.WizardDialog.finishPressed(WizardDialog.java:752)
    at plugin.wsreplication.ui.wizard.component.AddComponentWizardDialog.finishPressed(AddComponentWizardDialog.java:39)
    at org.eclipse.jface.wizard.WizardDialog.buttonPressed(WizardDialog.java:373)
    at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:624)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:228)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3910)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3503)
    at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
    at org.eclipse.jface.window.Window.open(Window.java:801)
    at plugin.wsreplication.ui.action.AddComponentAction.run(AddComponentAction.java:35)
    at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:251)

I am working on eclipse plugin which will have a wizard. This wizard will be available form example from context menu while mouse right click on Java editor.

The wizard will be responsible for collecting such information as:

  • location of WSDL file
  • Package name

When the wizard finishes, I would like to have stub of a webservice described in WSDL generated into package provided earlier.

THE QUESTION IS: How can I generate webservice stub dymanically and from source code (not from command line) and add it to the current project?

Until now, I came across WSDL2Java (Axis), Apache CXF and wsimport. I try to use Apache CXF and wsimport but I'm always getting ClassNotFoundException even though all jars are included into buildpath. I think I might have used them incorrectly.

Please help me folks! Time for that task is running out :-(

Little example:

Let's say the code is (Apache CXF):

String[] args = {"-client", "-d", "D:\\test", "D:\test.wsdl" };
WSDLToJava w = new WSDLToJava(args);
ToolContext t = new ToolContext();
w.run(t);

The first few lines of exception are:

java.lang.NoClassDefFoundError: org/apache/cxf/tools/wsdlto/WSDLToJava
    at plugin.wsreplication.ui.wizard.component.AddComponentWizard.performFinish(AddComponentWizard.java:160)
    at org.eclipse.jface.wizard.WizardDialog.finishPressed(WizardDialog.java:752)
    at plugin.wsreplication.ui.wizard.component.AddComponentWizardDialog.finishPressed(AddComponentWizardDialog.java:39)
    at org.eclipse.jface.wizard.WizardDialog.buttonPressed(WizardDialog.java:373)
    at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:624)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:228)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3910)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3503)
    at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
    at org.eclipse.jface.window.Window.open(Window.java:801)
    at plugin.wsreplication.ui.action.AddComponentAction.run(AddComponentAction.java:35)
    at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:251)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

谁对谁错谁最难过 2024-09-14 13:14:23

在我看来,cxf-tools 不在您的类路径上。

我不确定它如何与 Eclipse 插件和 OSGi 一起使用,以及如何为您的插件指定类路径,但您需要能够指定 CXF JAR 在类路径上的位置。

Sounds to me like cxf-tools is not on your Classpath.

I'm not sure how it works with Eclipse plugins and OSGi, and exactly how to specify a classpath for your plugin, but you need to be able to specify where the CXF JARs are on the classpath.

眼眸里的快感 2024-09-14 13:14:23

看来您在为插件设置环境时犯了一个错误。有关详细信息,请查看列表。
如果错误没有消失,请尝试使用 System.getProperty("java.class.path") 找出实际的类路径。如果 jar 确实位于类路径中,则问题可能出在 Eclipse 本身上。

It seems like you have done an error while setting up an environment for the plugin. Check this list for details.
If the error will not disappear, try to figure out an actual class path with System.getProperty("java.class.path"). If jar is really on a classpath, the problem may be in an Eclipse itself.

つ低調成傷 2024-09-14 13:14:23

我有同样的问题。在堆栈溢出中偶然发现了这个问题。我重新启动 eclipse 后问题就解决了。

该问题是由于 Eclipse 中未设置 Apache CXF jar 造成的。在 Eclipse 中设置 CXF 的主路径后。需要重新启动 Eclipse 才能拾取 jar。希望这对面临同样问题的人有帮助

I had the same issue. stumbled across this question in stack overflow. The issue got resolved as soon I restarted the eclipse.

The issue was due to Apache CXF jars not set in eclipse. Once the home path of CXF is set in eclipse. Eclipse needs to be restarted to pick up the jars.Hope this is helpful for someone who is facing the same issue

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文