Author Message
MichaelNorman
Joined: Jun 3, 2015
Messages: 448
Offline
Hello again. I'm attempting to add "swagger-codegen-maven-plugin" to pull in some automated code generation for an API I need to consume. While the code compiles correctly, I'm struggling with how to access that code from within the WAR java file.

My package files are following the standard project layout in /src/main/java/com/comcast/nco/MyService then MyCallListener.java etc.

The generated files based on the maven config go in /target/generated-sources/src/gen/java/main/io/swagger/, etc.

How can I access these files from within my Listener code?

This is the plug in code that was added to the WAR pom.xml--


<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>myurl</inputSpec>
<language>java</language>
<generateModels>true</generateModels>
<generateApis>false</generateApis>
<generateApiDocumentation>false</generateApiDocumentation>
<generateSupportingFiles>false</generateSupportingFiles>
<configOptions>
<sourceFolder>src/gen/java/main</sourceFolder>
<java8>true</java8>
<dateLibrary>java8-localdatetime</dateLibrary>
<library>jersey1</library>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
MichaelNorman
Joined: Jun 3, 2015
Messages: 448
Offline
I believe I figured this out using the below plugin to add-source. However a follow up question. How can I add code to the constructor of Listeners and web services? I attempted to just add via the below but, it doesn't appear to call my method:


public class MyCallListener extends CallListenerAbstract
{
public MyCallListener() {
super();
configureSEQ();
}



<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/swagger/src/main/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
JoelEzell
Joined: Nov 15, 2013
Messages: 780
Offline
Hello again Michael.

Thanks for letting us know that you figured out your build issue. One thing I was going to suggest is to use the "output" parameter for the swagger plugin to have it put the generated code into one of your own package directories instead of into the default target directory. I'm not a Maven expert, so I can't tell you which of those options is preferable.

Regarding your follow-on question, there is not a way to add code to the constructor, but you can utilize other mechanisms to perform operations on startup. If your application includes a CallListener, you can use the ServiceLifeCycle interface (make sure you use the "TheServiceLifeCycle" annotation). The Javadoc for this interface also shows how you can use standard JEE lifecycle methods in the case that your application uses only standard JEE objects and doesn't include a CallListener.

Let me know if that doesn't fully address your concerns.
Go to:   
Mobile view