我为here留了一个未解决的问题
我试图创建一个自定义代码生成器,我设法通过将文件放入代码生成器项目中来使其工作,但是我希望它像这样工作: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
创建服装代码生成在output / myLibrary中运行
mvn package
在包含swagger-codege-cli-2.1.6.jar和输出文件夹的文件夹中运行
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 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
我已经看过“错误:找不到或加载主类”问题的答案,但是还没有解决。
Here is a link to the jar
最佳答案
问题是您没有在呼叫中指定swagger-codegen-2.1.6.jar
的正确路径。这就是为什么它找不到main
类的原因。
如果您在根项目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
会有错误。请测试以下内容。将两个(
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.SwaggerCodegen
javap检查主类
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[]);
}