java - 使用 wsgen 时未找到类/名称错误

标签 java web-services wsgen

我遇到了 wsgen 问题,虽然我看到了一些有效的答案,但这些解决方案似乎都不适合我。我认为问题与源代码和二进制文件的结构有关。

我的 WSTest 项目设置了以下文件夹:

bin
└───com
    └───example
        └───ws
src
└───com
    └───example
        └───ws

主类是Test,它位于包com.example.ws中。

我使用以下命令从主项目文件夹 WSTest 运行 wsgen:

wsgen -cp ./bin/com/example/ws -d ./src/com/example/ws -s ./src/com/example/ws Test

这会导致:

Exception in thread "main" java.lang.NoClassDefFoundError (wrong name: com/example/ws/Test)

这是有道理的,因为该类是包的一部分。所以我将命令更改为以下内容:

wsgen -cp ./bin/com/example/ws -d ./src/com/example/ws -s ./src/com/example/ws com.example.ws.Test

但是现在我从 wsgen 工具中找不到类:

Class not found: "com.example.ws.Test"

Usage: WSGEN [options]

我错过了什么?

最佳答案

你尝试过这样的事情吗?

wsgen -cp ./bin -d ./src -s ./src com.example.ws.Test

类路径文件夹是 wsgen查找类文件。类中的包被解析为文件夹路径,因此 com.example.ws.Test应该是类似 com/example/ws/Test.class 的文件bin内类路径文件夹。

来自Java documentation :

Each classpath should end with a filename or directory depending on what you are setting the class path to:

  • For a .jar or .zip file that contains .class files, the class path ends with the name of the .zip or .jar file.
  • For .class files in an unnamed package, the class path ends with the directory that contains the .class files.
  • For .class files in a named package, the class path ends with the directory that contains the "root" package (the first package in the full package name).

关于java - 使用 wsgen 时未找到类/名称错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20599536/

相关文章:

java - XStream 使用 toXML(Object, StreamWriter) 缺少换行符

java - 小程序 - init()、EDT 和线程

web-services - Restful Web 服务认证

java - wsgen ant 任务忽略@webMethod(exclude=true) 注解

java - 找不到 Wsgen 类

java - 使用 RINGER_MODE_CHANGED 的广播接收器

java - 简单的java聊天服务器,仅向其他客户端而不是发送者广播

web-services - 服务器生成的网页截图?

.net - 如何从 Delphi Win32 应用程序访问 .Net Web 服务?

java - wsgen 使用 @WebMethod 生成 WSDL 但忽略 @WebParam