我正在从“Java Web Services Up and Running”一书中学习Java Web服务。 如上所述,我编译了这些类(代表“团队”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)
谢谢你的帮助。
答案 0 :(得分:1)
尝试在应用程序的根目录中执行wsgen
命令,而不是在ch01 / team目录中。我认为它应该可以工作,因为您在命令行中传递了包信息。
答案 1 :(得分:0)
基于@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
我希望它会帮助别人。