logo

Custom project structures for enterprise level WSO2 projects

When we are developing simple applications, most of the time we tend to use the standard project structures because those project structures are designed for general use cases. When it comes to enterprise level applications we might have to use custom project structures due to the architecture level design decisions.

As I mentioned in the WSO2 development best practices page, we should separate the environment specific dependencies from the logic so that we don’t have to touch the logic when we move from one environment to another. We can use the ESB Solution Project which comes with the WSO2 Developer Studio but there are some limitations in that project structure also.

Here I’m sharing two maven archetypes which you can use to create custom project structures for enterprise level applications.

  • Environment wise dependancy projects

In this option, you will have a separate registry artifacts project for each environment. So you have to duplicate the same artifact in each environment project and change the value or the content of the file relevant to the respective environment.

  • Parameterized environment dependencies

This project structure has only one registry artifacts project and the environment specific dependencies are parameterized. For example, if you have only the endpoints in the registry, you can parameterize the hostnames. For those kinds of projects, you can use this archetype when you are creating the project.

Of cause, we can create these project structures manually in the IDE, but using the archetype, we can have a consistency in all the projects within the organization and minimize the human errors when creating the projects.

How to configure the environment

If you want to use these archetypes please follow the steps to configure it before use. Please note that this needs to be done in the developer machine, which you are going to create the project structure, and this is a one time task.

Prerequisites

  • Java 1.8.0 or higher
  • Maven 3.0.x or higher
  • WSO2 Developer studio latest version

Steps

mvn install:install-file -Dfile=./wso2-services-solution-project-multi-env-archetype-1.0.0.jar -DgroupId=com.wso2.services.archetype -DartifactId=wso2-services-solution-project-multi-env-archetype -Dversion=1.0.0 -Dpackaging=jar -DgeneratePom=true
mvn install:install-file -Dfile=./wso2-services-parameterized-solution-project-archetype-1.0.0.jar -DgroupId=com.wso2.services.archetype -DartifactId=wso2-services-parameterized-solution-project-archetype -Dversion=1.0.0 -Dpackaging=jar -DgeneratePom=true
  • Create archetype-catalog.xml if you don’t have one in <USER_HOME>/.m2/repository/archetype-catalog.xml
  • Open the archetype-catalog.xml and update.
<?xml version="1.0" encoding="UTF-8"?>
<archetype-catalog xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-catalog/1.0.0 http://maven.apache.org/xsd/archetype-catalog-1.0.0.xsd"
   xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-catalog/1.0.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <archetypes>
   <archetype>
     <groupId>com.wso2.services.archetype</groupId>
     <artifactId>wso2-services-solution-project-multi-env-archetype</artifactId>
     <version>1.0.0</version>
     <description>wso2-services-solution-project-multi-env-archetype</description>
   </archetype>
   <archetype>
     <groupId>com.wso2.services.archetype</groupId>
     <artifactId>wso2-services-parameterized-solution-project-archetype</artifactId>
     <version>1.0.0</version>
     <description>wso2-services-parameterized-solution-project-archetype</description>
   </archetype>
 </archetypes>
</archetype-catalog>

Creating project structures using the archetypes

  • Execute the following command from where you want to store the project structure.
mvn archetype:generate -DarchetypeCatalog=local
  • Select the archetype from the list and continue the wizard.

  • Once you create the project, you can execute the following command to convert the newly created maven project compatible with Eclipse and import to the workspace.
mvn eclipse:eclipse 


that’s it. If you want to customize these archetypes, you can clone the GitHub repo [1] and update the archetype projects.

[1] https://github.com/dineshjweerakkody/wso2-maven-archetype

Comments are closed.