Generating own codegen modules issues

427 views
Skip to first unread message

Arseniy

unread,
Oct 26, 2015, 8:41:47 AM10/26/15
to Swagger
Hey, 

i've faced troubles with "making your own codegen modules" section from this doc
More specifically, after running the provided command

"java -jar modules/swagger-codegen-distribution/target/swagger-codegen-cli.jar meta -o output/myLibrary -n myClientCodegen -p com.my.company.codegen"

and building myLibrary (in the output directory) using

mvn package

i'm trying to follow appropriate advice (from output/myLibrary/Readme.md): "You can now use that with codegen:", so when i try to run

java -cp /path/to/swagger-codegen-distribution:/path/to/your/jar io.swagger.codegen.Codegen -l myClientCodegen -o ./test

which in my simple case equals

java -cp ../../modules/swagger-codegen-cli:target/myClientCodegen-swagger-codegen-1.0.0.jar io.swagger.codegen.Codegen -l myClientCodegen -o ./test

i've got following error:

"Error: Could not find or load main class io.swagger.codegen.Codegen"

What should i do to avoid this?
Any help will be appreciated.

tony tam

unread,
Oct 26, 2015, 7:44:38 PM10/26/15
to Swagger
Hi, a couple things.

First, you probably did successfully create a custom codegen module.  The error you're getting is because of how you're executing it.

There is the swagger-codegen-cli which is a runnable jar.  You can grab it from sonatype directly (http://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.1.4/) and run it with a simple command:


java
-jar swagger-codegen-cli-2.1.4.jar help


That should list all the default targets for generating.

Now, you've created a module which the above executable jar can find "automatically".  It just needs to be on your classpath:


java
-cp path/to/your/lib.jar -jar swagger-codegen-cli-2.1.4.jar help


That should list your project in the available languages.

Joven Albarida

unread,
Dec 1, 2015, 12:14:05 PM12/1/15
to Swagger
Hi,

I also encountering this issue, I've followed the answer from @tony tam

java -jar swagger-codegen-cli-2.1.4.jar help

java -cp path/to/your/lib.jar -jar swagger-codegen-cli-2.1.4.jar help

yes does code work, but when I tried to use this command

java -cp output/library/target/myJarcode-swagger-codegen-1.0.0.jar -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l myJarcode -o ./test


But it always throw this error:

Exception in thread "main" java.lang.RuntimeException: Can't load config class with name myJarcode Available: android
async-scala
csharp
....

I hope I can get some help with this? thanks in advance!

Btw, I've run this on Windows 7 OS, I also checked it on my Ubuntu Linux but throwing the same error message..


tony tam

unread,
Dec 2, 2015, 4:30:30 AM12/2/15
to swagger-sw...@googlegroups.com
Yes, you actually have to call it a bit differently when including your custom module along with the executable jar.

java -cp path/to/your/lib.jar:swagger-codegen-cli-2.1.4.jar io.swagger.codegen.SwaggerCodegen generate -l myJarcode


--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Iresha Udayangani

unread,
Feb 10, 2016, 8:50:56 AM2/10/16
to Swagger
java -cp output/library/target/myJarcode-swagger-codegen-1.0.0.jar -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l java -./test
worked for me.
It seems we need to give any option available as displayed by the excecption.
Reply all
Reply to author
Forward
0 new messages