wsgen引发NoClassDefFoundError异常



我正在从《Java web services Up and Running》这本书中学习Java web服务。如前所述,我编译了这些类(其中包含"Teams"web服务):

javac ch01/team/*.java
然后,当使用以下命令生成工件时(在"ch01/team目录"中完成):
wsgen -cp . ch01.team.Teams

我得到以下错误:

Exception in thread "main" java.lang.NoClassDefFoundError: Teams (wrong name: ch01/team/Teams)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at com.sun.tools.internal.ws.wscompile.WsgenOptions.getClass(WsgenOptions.java:276)
    at com.sun.tools.internal.ws.wscompile.WsgenOptions.validateEndpointClass(WsgenOptions.java:212)
    at com.sun.tools.internal.ws.wscompile.WsgenOptions.validate(WsgenOptions.java:203)
    at com.sun.tools.internal.ws.wscompile.WsgenTool.run(WsgenTool.java:111)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.tools.internal.ws.Invoker.invoke(Invoker.java:111)
    at com.sun.tools.internal.ws.WsGen.main(WsGen.java:41)

谢谢你的帮助

尝试在应用程序的根目录中执行wsgen命令,而不是在ch01/team目录中。当你在命令行中传递包信息时,我认为它应该可以工作。

根据@eternay给出的答案,以下是对我有效的方法:

 1. cd to project root directory
 2. issued wsgen -verbose -cp bin [package].ServiceImpl -wsdl
 3. "bin" being the root of .class files, and may be switched to "target" if you are using maven

我希望它能帮助到别人。

相关内容

  • 没有找到相关文章

最新更新