我遇到了 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
内类路径文件夹。
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/