我给这里留了个未知数
我正在尝试创建一个自定义编码,我设法通过将文件放入codegen项目来使其工作,但我希望它能像这样工作:https://github.com/swagger-api/swagger-codegen#making-your-own-codegen-modules。
我根本没有修改过自动生成的项目,但是我一直得到:
Error: Could not find or load main class io.swagger.codegen.SwaggerCodegen这是命令行:
java -cp output/myLibrary/target/myCustomCodegen-swagger-codegen-1.0.0.jar:swagger-codegen-cli-2.1.6.jar io.swagger.codegen.SwaggerCodegen generate -i https://watson-api-explorer.mybluemix.net/listings/conversation-v1-experimental.json -l com.my.company.codegen.Mycustomcodegengenerator -o outputlocation 我从这里拿到了罐子,https://mvnrepository.com/artifact/io.swagger/swagger-codegen-project/2.1.6,这就是我要做的:
java -jar swagger-codegen-cli-2.1.6.jar meta \ -o output/myLibrary -n myClientCodegen -p com.my.company.codegen创建服装代码mvn packagejava -cp output/myLibrary/target/myCustomCodegen-swagger-codegen-1.0.0.jar:swagger-codegen-cli-2.1.6.jar io.swagger.codegen.SwaggerCodegen generate -i https://watson-api-explorer.mybluemix.net/listings/conversation-v1-experimental.json -l com.my.company.codegen.Mycustomcodegengenerator -o outputlocation如果删除第一部分,它就会找到类,但是找不到新的语言:
java -cp swagger-codegen-cli-2.1.6.jar io.swagger.codegen.SwaggerCodegen generate -i https://watson-api-explorer.mybluemix.net/listings/conversation-v1-experimental.json -l com.my.company.codegen.Mycustomcodegengenerator -o outputlocation 我已经看过“错误:找不到或加载主类”问题的答案,但没有设法修复它。
发布于 2016-07-15 16:26:23
问题是您没有在调用中指定正确的swagger-codegen-2.1.6.jar路径。这就是为什么它找不到main-class。
如果您在根项目swagger-codegen中,您应该这样指定它:modules/swagger-codegen-cli/target/swagger-codegen-cli.jar
~$ cd ~/git/swagger-codegen # go into your root project
~/git/swagger-codegen$ # ... do the steps you described
~/git/swagger-codegen$ java -cp \
output/myLibrary/target/myClientCodegen-swagger-codegen-1.0.0.jar:modules/swagger-codegen-cli/target/swagger-codegen-cli.jar \
io.swagger.codegen.SwaggerCodegen \
generate -i https://watson-api-explorer.mybluemix.net/listings/conversation-v1-experimental.json \
-l com.my.company.codegen.Mycustomcodegengenerator \
-o outputlocation或者是一字一句:
~/git/swagger-codegen$ java -cp output/myLibrary/target/myClientCodegen-swagger-codegen-1.0.0.jar:modules/swagger-codegen-cli/target/swagger-codegen-cli.jar io.swagger.codegen.SwaggerCodegen generate -i https://watson-api-explorer.mybluemix.net/listings/conversation-v1-experimental.json -l com.my.company.codegen.Mycustomcodegengenerator -o outputlocation更新1
我非常肯定,当您使用-cp构造类路径时,swagger-codegen-cli-2.1.6.jar会出错。请测试以下内容。
将两个jars (myClientCodegen-swagger-codegen-1.0.0.jar和swagger-codegen-cli-2.1.6.jar)复制到同一个文件夹中。然后进入此文件夹并尝试以下操作:
javap -cp myCustomCodegen-swagger-codegen-1.0.0.jar:swagger-codegen-cli-2.1.6.jar io.swagger.codegen.SwaggerCodegenjavap检查主类io.swagger.codegen.SwaggerCodegen是否可用。在我的机器上印着这个:
Compiled from "SwaggerCodegen.java"
public class io.swagger.codegen.SwaggerCodegen {
public io.swagger.codegen.SwaggerCodegen();
public static void main(java.lang.String[]);
}发布于 2016-11-21 18:39:49
对于Windows,将类路径中jars之间的冒号(:)更改为分号(;)。所以而不是
java -cp output/myLibrary/target/myCustomCodegen-swagger-codegen-1.0.0.jar:swagger-codegen-cli-2.1.6.jar io.swagger.codegen.SwaggerCodegen generate -i https://watson-api-explorer.mybluemix.net/listings/conversation-v1-experimental.json -l com.my.company.codegen.Mycustomcodegengenerator -o outputlocation它应该是
java -cp output/myLibrary/target/myCustomCodegen-swagger-codegen-1.0.0.jar;swagger-codegen-cli-2.1.6.jar io.swagger.codegen.SwaggerCodegen generate -i https://watson-api-explorer.mybluemix.net/listings/conversation-v1-experimental.json -l com.my.company.codegen.Mycustomcodegengenerator -o outputlocation多个类路径需要用分号分隔。http://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html
发布于 2021-05-21 22:21:33
在运行macOS 10.14中的Eclipse4.19中的Spring应用程序时,我遇到了类似的问题:
“错误:找不到或加载主类io.swagger.Swagger2SpringBoot”
…就在我盯着这个包含主要方法的类的时候。我的解决方案是发布一个"maven更新项目“。这和其他带有奇怪Java症状的情况一样,解决了这个问题。
https://stackoverflow.com/questions/38334597
复制相似问题