Welcome!

Industrial IoT Authors: Pat Romanski, Elizabeth White, Maria C. Horton, Liz McMillan, Ed Featherston

Blog Feed Post

Creating maven archetype using create-from-project

Maven archetypes are a great way to create templates for standardized projects. The advantage of creating a maven archetype is that it can easily integrate with any IDE that supports maven compilation such as Eclipse. In SMART we provide maven archetypes to get started on developing SMART flows easily. In this blog I want to share our learning when creating these archetypes.

Sample Archetype

We will write an archetype called simple-archetype that generates the following structure:

    pom.xml
    src
     |--main
        |-- java
        |   |-- package (org.smart.demo)
        |       |-- TestMessage.java
        |-- resources
            |-- TestMessageFlow.soa
            |-- package (org.smart.demo)
                |-- TestMessage.soa

when the below command is run:

 mvn archetype:generate \
-DarchetypeGroupId=org.smart.archetypes \
-DarchetypeArtifactId=simple-archetype \  
-DarchetypeVersion=1.0-SNAPSHOT \  
-DgroupId=org.smart.demo \  
-DartifactId=testmessage \  
-Dclassname=TestMessage

Creating the skeleton archetype project

Maven archetypes can be created easily using the create-from-project maven command. To create an archetype from a project run the command from the directory where the template project is present.

mvn archetype:create-from-project

We will use the sample template project from here to create the archetype. This creates an archetype from the current project into the directory target/generated-sources/archetype. When we look at the generated project for the archetype we find that Message.java is hardcoded. Hence using this archetype will always only generate back the same fields and java classes as present in the template project.

archetype properties

How to vary the generated class? By default maven has a set of standard variables defined that can be varied when the project is created. The most common ones that are used:

  • groupId
  • artifactId
  • version
  • package

These are defaulted to the values in the project from which the artefact is created. More variables can be added to this as required for the archetype. For eg., in our project we want to vary the name of Message.java, to do this we will introduce a new variable called “data” that can be specified when the maven project is created.

The maven create-from-project takes in a archetype properties file that define these variables. To use this we define a generate.properties file with content as below (Ensure this file is present outside the directory of your template project):

package=org.smart.flows.message
groupId=org.smart.flows
artifactId=message
version=1.0-SNAPSHOT
data=Message

The values should be the values that are present in the template project. In our example, we have the data class in the package org.smart.flows.message and it is called Message.java. Hence we have defined the “data” variable as Message. This is important because the create-from-project will automatically replace the values with the variables. Now you can run the command as

mvn -Darchetype.properties=../generate.properties archetype:create-from-project

The Message.java that is generated will be as below:

#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${groupId}.${artifactId};

public class ${data} implements java.io.Serializable
{
    private String ${artifactId};

    public ${data}()
    {
    }

    public String get${data}() { return ${artifactId}; }
}

Now the content of the java file will vary based on the “data” and “artifactId” variables set. The generated project has a few things that has to be fixed.

  • The name of the java file is still hardcoded to Message.java.
  • The files in resources directory is still hardcoded with Message

Changing the name of the generated file

The files that will be used to generate the project is present under the directory “src/main/resources/archetype-resources/”. The java file is under “src/main/java”. Move the Message.java file to  __data__.java. This will ensure that the generated file is the same name as the variable passed to the maven command. The package variable is not correct, since the artifactId and groupId reflect the package name. Hence we change the package from ${groupId}.${artifactId} to ${package}. This sets up the java class correctly.

The test classes also need to follow the same pattern, except the file has to have a “Test” post fixed to the name. Hence we rename the test file as __data__Test.java. Any variations in the java classes can be done manually. Any ${…} inside the file is substituted with the variable value and __…__ in the file name is substituted with the variable value.

Changing the resources directory

While the java classes are by default created with substitution variables, the resources are not. These files need to be modified manually. In our case we have two files to be generated. Flow.soa that describes our jar.The .soa describes our data class and has to be present in the same package as the java class. Modification for substitution is simple. The soa file is changed as below:

##set( $symbol_pound = '#' )
##set( $symbol_dollar = '$' )
##set( $symbol_escape = '\' )
name:   ${data}Flow
defaultEnable: all
primeData:
    - ${package}.${data}
events:
    - ${package}.${event}
transitions:
    - ${package}.${transition}
features:
    - name: all
      artefacts:
        - ${package}.${data}
        - ${package}.${event}
        - ${package}.${transition}

We need to add the first three lines in all files. This has to be equal to a comment, hence we use “##”. We replace all places where substitution has to occur with the proper variables. This generates the file with the correct substitutions. But changing the name of the file to “__data__Flow.soa” does not change the file name based on the variable.

To do this we need to change the archetype metadata. This is present under the directory “src/main/resources/META-INF/maven/” in the file archetype-metadata.xml. The fileset command in this file defines how the files are created:

  

    <fileSet filtered="true" packaged="true" encoding="UTF-8">
      src/main/java

        **/*.java

    <fileSet encoding="UTF-8">
      src/main/resources

        **/*.soa

    
    <fileSet filtered="true" packaged="true" encoding="UTF-8">
      src/test/java

        **/*.java

From the above we see that the resources directory is a direct copy. To change this we need two variables defined, filtered and packaged. So we redefine this as below:

    <fileSet encoding="UTF-8" packaged="true" filtered="true">
      src/main/resources

        **/__*__.soa

    filtered="true">
      src/main/resources

        **/*Flow.soa
        **/*.js

We need the Flow.soa directly under the parent directory while the .soa file needs to be present in the packaged directory. Hence we split this into two filesets. Now we rename the files appropriately i.e., MessageFlow.soa is named as __data__Flow.soa and Message.soa is directly under the resources directory and named as __data__.soa file. This ensures that we get the correct project generated when the maven command is run.The generated maven archetype can be checked out here.


Read the original blog entry...

More Stories By Raji Sankar

Raji Sankar is a techie at heart trying his hand at entrepreneur-ship. He is Co-Founder and Director of BrioTribes Technologies India Pvt Ltd. based out of Bangalore. He likes to try out anything that is new, interesting and cutting edge. His latest passion is cloud and creating an application platform for the cloud. Check out SMART the documentation for the open-source cloud application platform here and the demo for the platform here

@ThingsExpo Stories
Organizations planning enterprise data center consolidation and modernization projects are faced with a challenging, costly reality. Requirements to deploy modern, cloud-native applications simultaneously with traditional client/server applications are almost impossible to achieve with hardware-centric enterprise infrastructure. Compute and network infrastructure are fast moving down a software-defined path, but storage has been a laggard. Until now.
In his general session at 19th Cloud Expo, Manish Dixit, VP of Product and Engineering at Dice, discussed how Dice leverages data insights and tools to help both tech professionals and recruiters better understand how skills relate to each other and which skills are in high demand using interactive visualizations and salary indicator tools to maximize earning potential. Manish Dixit is VP of Product and Engineering at Dice. As the leader of the Product, Engineering and Data Sciences team at D...
DXWorldEXPO LLC announced today that the upcoming DXWorldEXPO | CloudEXPO New York event will feature 10 companies from Poland to participate at the "Poland Digital Transformation Pavilion" on November 12-13, 2018.
Digital Transformation is much more than a buzzword. The radical shift to digital mechanisms for almost every process is evident across all industries and verticals. This is often especially true in financial services, where the legacy environment is many times unable to keep up with the rapidly shifting demands of the consumer. The constant pressure to provide complete, omnichannel delivery of customer-facing solutions to meet both regulatory and customer demands is putting enormous pressure on...
The best way to leverage your CloudEXPO | DXWorldEXPO presence as a sponsor and exhibitor is to plan your news announcements around our events. The press covering CloudEXPO | DXWorldEXPO will have access to these releases and will amplify your news announcements. More than two dozen Cloud companies either set deals at our shows or have announced their mergers and acquisitions at CloudEXPO. Product announcements during our show provide your company with the most reach through our targeted audienc...
JETRO showcased Japan Digital Transformation Pavilion at SYS-CON's 21st International Cloud Expo® at the Santa Clara Convention Center in Santa Clara, CA. The Japan External Trade Organization (JETRO) is a non-profit organization that provides business support services to companies expanding to Japan. With the support of JETRO's dedicated staff, clients can incorporate their business; receive visa, immigration, and HR support; find dedicated office space; identify local government subsidies; get...
DXWorldEXPO LLC announced today that All in Mobile, a mobile app development company from Poland, will exhibit at the 22nd International CloudEXPO | DXWorldEXPO. All In Mobile is a mobile app development company from Poland. Since 2014, they maintain passion for developing mobile applications for enterprises and startups worldwide.
@DevOpsSummit at Cloud Expo, taking place November 12-13 in New York City, NY, is co-located with 22nd international CloudEXPO | first international DXWorldEXPO and will feature technical sessions from a rock star conference faculty and the leading industry players in the world.
"Akvelon is a software development company and we also provide consultancy services to folks who are looking to scale or accelerate their engineering roadmaps," explained Jeremiah Mothersell, Marketing Manager at Akvelon, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
As data explodes in quantity, importance and from new sources, the need for managing and protecting data residing across physical, virtual, and cloud environments grow with it. Managing data includes protecting it, indexing and classifying it for true, long-term management, compliance and E-Discovery. Commvault can ensure this with a single pane of glass solution – whether in a private cloud, a Service Provider delivered public cloud or a hybrid cloud environment – across the heterogeneous enter...
DXWorldEXPO LLC announced today that ICC-USA, a computer systems integrator and server manufacturing company focused on developing products and product appliances, will exhibit at the 22nd International CloudEXPO | DXWorldEXPO. DXWordEXPO New York 2018, colocated with CloudEXPO New York 2018 will be held November 11-13, 2018, in New York City. ICC is a computer systems integrator and server manufacturing company focused on developing products and product appliances to meet a wide range of ...
More and more brands have jumped on the IoT bandwagon. We have an excess of wearables – activity trackers, smartwatches, smart glasses and sneakers, and more that track seemingly endless datapoints. However, most consumers have no idea what “IoT” means. Creating more wearables that track data shouldn't be the aim of brands; delivering meaningful, tangible relevance to their users should be. We're in a period in which the IoT pendulum is still swinging. Initially, it swung toward "smart for smart...
Headquartered in Plainsboro, NJ, Synametrics Technologies has provided IT professionals and computer systems developers since 1997. Based on the success of their initial product offerings (WinSQL and DeltaCopy), the company continues to create and hone innovative products that help its customers get more from their computer applications, databases and infrastructure. To date, over one million users around the world have chosen Synametrics solutions to help power their accelerated business or per...
Dion Hinchcliffe is an internationally recognized digital expert, bestselling book author, frequent keynote speaker, analyst, futurist, and transformation expert based in Washington, DC. He is currently Chief Strategy Officer at the industry-leading digital strategy and online community solutions firm, 7Summits.
In an era of historic innovation fueled by unprecedented access to data and technology, the low cost and risk of entering new markets has leveled the playing field for business. Today, any ambitious innovator can easily introduce a new application or product that can reinvent business models and transform the client experience. In their Day 2 Keynote at 19th Cloud Expo, Mercer Rowe, IBM Vice President of Strategic Alliances, and Raejeanne Skillern, Intel Vice President of Data Center Group and ...
Founded in 2000, Chetu Inc. is a global provider of customized software development solutions and IT staff augmentation services for software technology providers. By providing clients with unparalleled niche technology expertise and industry experience, Chetu has become the premiere long-term, back-end software development partner for start-ups, SMBs, and Fortune 500 companies. Chetu is headquartered in Plantation, Florida, with thirteen offices throughout the U.S. and abroad.
Bill Schmarzo, author of "Big Data: Understanding How Data Powers Big Business" and "Big Data MBA: Driving Business Strategies with Data Science," is responsible for setting the strategy and defining the Big Data service offerings and capabilities for EMC Global Services Big Data Practice. As the CTO for the Big Data Practice, he is responsible for working with organizations to help them identify where and how to start their big data journeys. He's written several white papers, is an avid blogge...
"We are a well-established player in the application life cycle management market and we also have a very strong version control product," stated Flint Brenton, CEO of CollabNet,, in this SYS-CON.tv interview at 18th Cloud Expo at the Javits Center in New York City, NY.
It is of utmost importance for the future success of WebRTC to ensure that interoperability is operational between web browsers and any WebRTC-compliant client. To be guaranteed as operational and effective, interoperability must be tested extensively by establishing WebRTC data and media connections between different web browsers running on different devices and operating systems. In his session at WebRTC Summit at @ThingsExpo, Dr. Alex Gouaillard, CEO and Founder of CoSMo Software, presented ...
Most people haven’t heard the word, “gamification,” even though they probably, and perhaps unwittingly, participate in it every day. Gamification is “the process of adding games or game-like elements to something (as a task) so as to encourage participation.” Further, gamification is about bringing game mechanics – rules, constructs, processes, and methods – into the real world in an effort to engage people. In his session at @ThingsExpo, Robert Endo, owner and engagement manager of Intrepid D...