<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Shima Abbasi on Medium]]></title>
        <description><![CDATA[Stories by Shima Abbasi on Medium]]></description>
        <link>https://medium.com/@shimaabbasi?source=rss-ca838d7dfb8e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*rSBjKvK6cT1tNapRhYkwsw.jpeg</url>
            <title>Stories by Shima Abbasi on Medium</title>
            <link>https://medium.com/@shimaabbasi?source=rss-ca838d7dfb8e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 07:02:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shimaabbasi/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A Guide to Combining JARs with Maven Antrun Plugin]]></title>
            <link>https://medium.com/@shimaabbasi/a-guide-to-combining-jars-with-maven-antrun-plugin-1ffeadca13dd?source=rss-ca838d7dfb8e------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ffeadca13dd</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[maven-plugin]]></category>
            <category><![CDATA[jar]]></category>
            <category><![CDATA[maven]]></category>
            <dc:creator><![CDATA[Shima Abbasi]]></dc:creator>
            <pubDate>Sun, 29 Sep 2024 13:01:46 GMT</pubDate>
            <atom:updated>2024-09-29T13:01:46.610Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1yxOqgIoG4LAQVipP5uhqQ.jpeg" /></figure><h3>Introduction</h3><p>In Java development, managing multi-module projects can be a complex task. One common challenge is combining multiple JAR files into a single JAR for easier deployment and distribution. In this article, I’ll walk you through a Maven project that achieves this using the Antrun plugin.</p><p>Combining JAR files can significantly simplify the deployment process, reduce the complexity of managing dependencies, and streamline the distribution of your application. Instead of juggling multiple JARs, you can have a single, consolidated JAR file that contains all the necessary components, including all classes from the various modules. This unified approach ensures that everything your application needs is packaged together, making it easier to manage and deploy.</p><h3>Project Structure</h3><p>In a multi-module Maven project, the main module has its own pom.xml, and each sub-module also has its own pom.xml. The main module’s POM should refer to the sub-modules in the order of priority for compilation. The last module in this sequence should be the combiner module, which combines all the JAR files from the other modules we specified. This ensures that all modules are compiled before the final JAR is created.</p><p>Here’s an example of how the structure is defined in the main module’s pom.xml:</p><pre>    &lt;groupId&gt;com&lt;/groupId&gt;<br>    &lt;artifactId&gt;combine-multipe-jars&lt;/artifactId&gt;<br>    &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;<br>    &lt;packaging&gt;pom&lt;/packaging&gt;<br>    &lt;modules&gt;<br>        &lt;module&gt;sample-module-one&lt;/module&gt;<br>        &lt;module&gt;sample-module-two&lt;/module&gt;<br>        &lt;module&gt;combined&lt;/module&gt;<br>    &lt;/modules&gt;</pre><p>In this structure:</p><ul><li>sample-module-one and sample-module-two are the individual modules with their own pom.xml files.</li><li>combine is the module responsible for combining the JAR files from the other modules.</li><li>In each sub-module, we refer to the main module with the following configuration:</li></ul><pre>&lt;parent&gt;<br>    &lt;groupId&gt;com&lt;/groupId&gt;<br>    &lt;artifactId&gt;combine-multipe-jars&lt;/artifactId&gt;<br>    &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;<br>&lt;/parent&gt;</pre><ul><li>Be careful that the packaging in the main module’s pom.xml should be set to pom.</li></ul><h3>Using the Antrun Plugin to Combine JAR Files</h3><p>The Antrun plugin allows us to run Ant tasks within a Maven build. This flexibility enables us to perform custom-build tasks, such as combining multiple JAR files into a single JAR. Here’s how you can configure the Antrun plugin in your Maven project:</p><ol><li><strong>Add the Antrun Plugin:</strong></li></ol><p>First, you need to add the Antrun plugin to the pom.xml file of your combiner module. This configuration specifies that the plugin should run during the package phase of the Maven build lifecycle.</p><pre>&lt;plugin&gt;<br>  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;<br>  &lt;artifactId&gt;maven-antrun-plugin&lt;/artifactId&gt;<br>  &lt;version&gt;${maven-antrun-plugin.version}&lt;/version&gt;<br>  &lt;executions&gt;<br>      &lt;execution&gt;<br>          &lt;id&gt;combine-jars&lt;/id&gt;<br>          &lt;phase&gt;package&lt;/phase&gt;<br>          &lt;goals&gt;<br>              &lt;goal&gt;run&lt;/goal&gt;<br>          &lt;/goals&gt;<br>          &lt;configuration&gt;<br>              &lt;target&gt;<br>                  &lt;mkdir dir=&quot;${project.build.directory}&quot;/&gt;<br>                  &lt;jar destfile=&quot;${project.build.directory}/${project.artifactId}-${project.version}.jar&quot;&gt;<br>                      &lt;fileset dir=&quot;../sample-module-one/target/classes&quot;&gt;<br>                          &lt;include name=&quot;**/*.class&quot;/&gt;<br>                      &lt;/fileset&gt;<br>                      &lt;fileset dir=&quot;../sample-module-two/target/classes&quot;&gt;<br>                          &lt;include name=&quot;**/*.class&quot;/&gt;<br>                      &lt;/fileset&gt;<br>                  &lt;/jar&gt;<br>              &lt;/target&gt;<br>          &lt;/configuration&gt;<br>      &lt;/execution&gt;<br>  &lt;/executions&gt;<br>&lt;/plugin&gt;</pre><p>Keep in mind that the packaging in combined pom should be “jar,” as shown below:</p><pre>   &lt;packaging&gt;jar&lt;/packaging&gt;</pre><p>2. <strong>Run the Maven Package Command</strong></p><p>After configuring the Antrun plugin, you can combine the JAR files by running the Maven package command. This command will compile all the modules and then use the Antrun plugin to combine their JAR files into a single JAR.</p><pre>mvn clean package</pre><h3><strong>Explanation of the Key Parts:</strong></h3><ol><li>This task creates a JAR file. The destfile attribute specifies the destination file path for the combined JAR.</li></ol><pre>&lt;jar destfile=&quot;${project.build.directory}/${project.artifactId}-${project.version}.jar&quot;&gt;</pre><p>2. The &lt;fileset&gt; element specifies the directory containing the class files to be included in the JAR. The dir attribute points to the target/classes directory of the sample-module-one module. Additional &lt;fileset&gt; elements can be added, including class files from different modules.</p><pre>&lt;fileset dir=&quot;../sample-module-one/target/classes&quot;&gt;</pre><p>3. This element specifies the pattern for the files to be included in the JAR. This case includes all .class files in the specified directory and its subdirectories.</p><pre>&lt;include name=&quot;**/*.class&quot;/&gt;</pre><h3>Final Structure of the Combined JAR File</h3><pre>combined-jar-1.0-SNAPSHOT.jar<br>├── com/<br>│   ├── example/<br>│   │   ├── sample-module-one/<br>│   │   │   └── SampleClassOne.class<br>│   │   ├── sample-module-two/<br>│   │   │   └── SampleClassTwo.class<br>│   │   └── ...<br>└── META-INF/<br>    └── MANIFEST.MF</pre><p>This structure shows how the class files from sample-module-one and sample-module-two are included in the final combined JAR file, simplifying your application’s deployment and distribution.</p><h3>Conclusion</h3><p>Using the Antrun plugin in a Maven project, you can easily combine multiple module JAR files into a single JAR. This approach simplifies deployment and makes managing your Java projects more efficient. Let’s make everything more accessible and more streamlined!</p><p>For the complete code and further details, check out my <a href="https://github.com/shima-abbasi/multi-module-jar-combiner">GitHub repository</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ffeadca13dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Generate Classes from Swagger OAS 3 with a Custom OpenAPI Generator in a Maven Project]]></title>
            <link>https://medium.com/@shimaabbasi/how-to-generate-classes-from-swagger-oas-3-with-a-custom-openapi-generator-in-a-maven-project-46b35e0d9649?source=rss-ca838d7dfb8e------2</link>
            <guid isPermaLink="false">https://medium.com/p/46b35e0d9649</guid>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[quarkus]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[openapi-generator]]></category>
            <category><![CDATA[maven]]></category>
            <dc:creator><![CDATA[Shima Abbasi]]></dc:creator>
            <pubDate>Sat, 28 Sep 2024 20:48:38 GMT</pubDate>
            <atom:updated>2024-09-28T20:52:43.978Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>In this tutorial, I’ll guide you through setting up a Maven-based Java project to generate API and model classes from a Swagger OpenAPI Specification (OAS) 3.0 document. We’ll use a custom OpenAPI generator built on top of the <a href="https://github.com/OpenAPITools/openapi-generator">OpenAPITools</a> code generator and deploy an example API on Azure using Quarkus.</p><h3>1. Setting Up a Simple Swagger File</h3><p>To get started, let’s create a simple Swagger file. This file will define the API endpoints, request parameters, and responses. Below is an example of a basic Swagger OAS 3.0 file:</p><pre>openapi: 3.0.0<br>info:<br>  title: Simple API<br>  description: A simple example API for demonstrating Swagger file generation.<br>  version: 1.0.0<br>servers:<br>  - url: /api<br>tags:<br>  - name: User<br>    description: Operations related to users<br><br>paths:<br>  /users:<br>    get:<br>      tags:<br>        - User<br>      summary: Get list of users<br>      operationId: getUsers<br>      responses:<br>        &#39;200&#39;:<br>          description: Successful operation<br>          content:<br>            application/json:<br>              schema:<br>                type: array<br>                items:<br>                  $ref: &#39;#/components/schemas/User&#39;<br>        &#39;500&#39;:<br>          description: Internal Server Error<br>      parameters:<br>        - name: limit<br>          in: query<br>          description: Maximum number of users to return<br>          required: false<br>          schema:<br>            type: integer<br>            format: int32<br>        - name: offset<br>          in: query<br>          description: Offset for pagination<br>          required: false<br>          schema:<br>            type: integer<br>            format: int32<br><br>components:<br>  schemas:<br>    User:<br>      type: object<br>      properties:<br>        id:<br>          type: string<br>          description: The unique identifier of the user<br>        name:<br>          type: string<br>          description: The name of the user<br>        email:<br>          type: string<br>          description: The email of the user<br>      required:<br>        - id<br>        - name</pre><h3>2. Adding a Custom Code Generator</h3><p>We should create a custom code generator class to customize the code generation process. Below is the code for our custom code generator:</p><pre><br>import org.openapitools.codegen.CodegenConfig;<br>import org.openapitools.codegen.languages.JavaClientCodegen;<br><br>public class CustomCodegen extends JavaClientCodegen implements CodegenConfig {<br><br>  protected String customPackage = &quot;com.custom.codegen.openapitools&quot;;<br><br>  public CustomCodegen() {<br>    this.setOutputDir(&quot;src/main/java&quot;);<br>    this.setLibrary(&quot;resteasy&quot;);<br>    this.setModelPackage(customPackage + &quot;.model&quot;);<br>    this.setApiPackage(customPackage + &quot;.api&quot;);<br>  }<br><br>  @Override<br>  public String getName() {<br>    return &quot;customCodegen&quot;;<br>  }<br><br>  @Override<br>  public void processOpts() {<br>    super.processOpts();<br>    apiTemplateFiles.clear();<br>    modelTemplateFiles.clear();<br>    apiDocTemplateFiles.clear();<br>    apiTestTemplateFiles.clear();<br>    modelTestTemplateFiles.clear();<br>    supportingFiles.clear();<br>    modelDocTemplateFiles.clear();<br><br>    // Register Mustache templates for API generation<br>    apiTemplateFiles.put(&quot;api.mustache&quot;, &quot;.java&quot;);<br><br>    // Add any additional template files (like models if needed)<br>    modelTemplateFiles.put(&quot;model.mustache&quot;, &quot;.java&quot;);<br>  }<br>}</pre><h3>3. Adding Mustache Template Files</h3><p>We should create Mustache template files and place them in the resource directory to customize the generated code. The custom code generator will use these templates to produce the desired output.</p><p>You can customize Mustache template files based on your project requirements from the <a href="https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator/src/main/resources">OpenAPITools repository</a>.</p><h3>4. Using the OpenAPITools Plugin in POM</h3><p>When using the OpenAPITools plugin in your POM file, there are a couple of tricky points to keep in mind:</p><p><strong>1. Adding Project Dependency to the Plugin</strong></p><p>To register your custom code generator, you should add your project as a dependency to the plugin. This ensures that the plugin can recognize and use your custom generator. Without this step, you’ll encounter an error indicating that the generator name is not recognized and suggesting available values.</p><p>Additionally, you should reference your Swagger file and template folder in the plugin configuration. This allows the plugin to know where to find the OpenAPI specification and the templates for code generation.</p><p>Here’s an example configuration:</p><pre>&lt;plugin&gt;<br>    &lt;groupId&gt;org.openapitools&lt;/groupId&gt;<br>    &lt;artifactId&gt;openapi-generator-maven-plugin&lt;/artifactId&gt;<br>    &lt;version&gt;${openapi-generator-maven-plugin.version}&lt;/version&gt;<br>    &lt;dependencies&gt;<br>        &lt;dependency&gt;<br>            &lt;groupId&gt;${project.groupId}&lt;/groupId&gt;<br>            &lt;artifactId&gt;${project.artifactId}&lt;/artifactId&gt;<br>            &lt;version&gt;${project.version}&lt;/version&gt;<br>        &lt;/dependency&gt;<br>    &lt;/dependencies&gt;<br>    &lt;executions&gt;<br>        &lt;execution&gt;<br>            &lt;id&gt;generate-user&lt;/id&gt;<br>            &lt;goals&gt;<br>                &lt;goal&gt;generate&lt;/goal&gt;<br>            &lt;/goals&gt;<br>            &lt;phase&gt;validate&lt;/phase&gt;<br>            &lt;configuration&gt;<br>                &lt;generatorName&gt;com.shima.openapitools.codegen.CustomCodegen&lt;/generatorName&gt;<br>                &lt;inputSpec&gt;${project.basedir}/src/main/resources/openapi/user.yaml&lt;/inputSpec&gt;<br>                &lt;templateDirectory&gt;${project.basedir}/src/main/resources/openapi-templates&lt;/templateDirectory&gt;<br>            &lt;/configuration&gt;<br>        &lt;/execution&gt;<br>    &lt;/executions&gt;<br>&lt;/plugin&gt;</pre><p><strong>2. Compiling Custom Codegen in the Validate Phase</strong></p><p>Compiling your custom code generator during validation ensures it is compiled and available when the OpenAPITools plugin runs. You can achieve this by configuring the Maven Compiler Plugin accordingly.</p><p>Here’s an example configuration:</p><pre>&lt;plugin&gt;<br>    &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;<br>    &lt;version&gt;${compiler-plugin.version}&lt;/version&gt;<br>    &lt;configuration&gt;<br>        &lt;source&gt;${java.version}&lt;/source&gt;<br>        &lt;target&gt;${java.version}&lt;/target&gt;<br>    &lt;/configuration&gt;<br>    &lt;executions&gt;<br>        &lt;execution&gt;<br>            &lt;id&gt;compile-custom-codegen&lt;/id&gt;<br>            &lt;phase&gt;validate&lt;/phase&gt;<br>            &lt;goals&gt;<br>                &lt;goal&gt;compile&lt;/goal&gt;<br>            &lt;/goals&gt;<br>            &lt;configuration&gt;<br>                &lt;compileSourceRoots&gt;<br>                    &lt;compileSourceRoot&gt;${project.basedir}/src/main/java/com/shima/openapitools/codegen&lt;/compileSourceRoot&gt;<br>                &lt;/compileSourceRoots&gt;<br>            &lt;/configuration&gt;<br>        &lt;/execution&gt;<br>    &lt;/executions&gt;<br>&lt;/plugin&gt;</pre><h3>5. Building the Project</h3><p>After configuring the plugins, you can build your project. This will generate the necessary classes based on your OpenAPI specification. To build the project, run the following Maven command:</p><pre>mvn clean install</pre><p>After the build completes, you will find the generated classes in the target Folder. The structure will look something like this:</p><p>target/<br>├── generated-sources/<br>│ └── openapi/<br>│ ├── api/<br>│ ├── model/<br>│ └── …<br>└── …</p><h3>6. Using the API in a Sample Azure Function Class</h3><p>Once you have generated the necessary classes from your OpenAPI specification, you can use them in an Azure Function to create a serverless API endpoint. Below is an example of how to do this:</p><pre><br>import java.util.Map;<br>import java.util.Optional;<br><br>import com.microsoft.azure.functions.*;<br>import com.microsoft.azure.functions.annotation.*;<br>import com.custom.codegen.openapitools.api.UserApi;<br>import jakarta.enterprise.context.ApplicationScoped;<br>import jakarta.inject.Inject;<br>import jakarta.ws.rs.core.Response;<br>import lombok.extern.slf4j.Slf4j;<br>import org.eclipse.microprofile.rest.client.inject.RestClient;<br><br>/**<br> * Azure Function that handles a simple GET request.<br> */<br><br>@Slf4j<br>@ApplicationScoped<br>public class ExampleGetApi {<br><br>  private final UserApi userApi;<br><br>  @Inject<br>  public ExampleGetApi(@RestClient UserApi userApi) {<br>    this.userApi = userApi;<br>  }<br><br>  @FunctionName(&quot;exampleGetApi&quot;)<br>  public HttpResponseMessage getExample<br>      (@HttpTrigger(name = &quot;req&quot;,<br>          methods = {HttpMethod.GET},<br>          route = &quot;test&quot;,<br>          authLevel = AuthorizationLevel.FUNCTION)<br>       HttpRequestMessage&lt;Optional&lt;String&gt;&gt; request) {<br><br>    final Map&lt;String, String&gt; headers = request.getHeaders();<br><br>    try {<br>      return handleRequest(request, headers);<br>    } catch (Exception e) {<br>      log.error(&quot;Error handling request: {}&quot;, e.getMessage());<br>      return request.createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR).body(&quot;{ \&quot;status\&quot;:\&quot;&quot; + e.getMessage() + &quot;\&quot; }&quot;).build();<br>    }<br>  }<br><br>  private HttpResponseMessage handleRequest(HttpRequestMessage&lt;Optional&lt;String&gt;&gt; request, Map&lt;String, String&gt; headers) {<br><br>    log.info(&quot;Request received&quot;);<br><br>    //TODO :Placeholder for custom logic<br><br>    Response response = userApi.getUsers(2, 1);<br><br>    return request.createResponseBuilder(HttpStatus.OK).body(response.getEntity()).build();<br>  }<br>}</pre><p>You can run the project using the following Maven command:</p><pre>mvn azure-functions:run</pre><h3>Conclusion</h3><p>Following these steps, you can ensure that your custom code generator is appropriately registered, compiled, and used to generate the necessary classes from your OpenAPI specification. For the complete code and further details, check out my <a href="https://github.com/shima-abbasi/custom-codegen-openapitools">GitHub repository</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=46b35e0d9649" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>