java -D command-line option

-D command-line option explained

Can be used to set an environment value on a CLI which is the accessible from code by :
String value = System.getProperty("key", "defaultvalue");

Generate a CLI shell with Maven

Online Info: appassembler-maven-plugin

Steps to get a fully packaged test app are as follows:

1. run maven archetype to create a basic CLI app
$ mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app

2. Add maven plugin configuration for the appassembler-maven-plugin
<build>
  <plugins>
    <!-- package the app into a jar -->
  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>appassembler-maven-plugin</artifactId>
    <version>${appassembler-maven-plugin-version}</version> <!-- 1.0 -->
  <configuration>
<extraJvmArguments>-Xms128m -Xmx512m</extraJvmArguments>
  <programs>
    <program>
      <mainClass>com.mycompany.app.App</mainClass>
      <name>testApp</name>
    </program>
  </programs>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>assemble</goal>
</goals>
</execution>
</executions>
</plugin>

<!-- use the archive.xml to package up a deployable .zip file -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>${maven-assembly-plugin-version}</version>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/archive.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

</build>


3. Add in proper archiving configuration
in assembly\archive.xml
example:
  <assembly>
    <id>appassembly</id>
      <formats>
        <format>zip</format>
      </formats>
    <fileSets>
<fileSet>
<directory>target/appassembler</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
<!--fileSet>
<directory>bin</directory>
<outputDirectory>/bin</outputDirectory>
</fileSet-->
<!-- add any other filesets to include docs, readmes, licences etc here -->
</fileSets>
</assembly>


When completed, run maven clean install. The generated .ZIP file can then can be unpackaged
and deployed where desired. In the deployed bin directory, a .bat file will properly run the CLI app.

Creating a empty maven project structure

Maven can itself create empty project structures when you want to start a new code base. To create an empty project structure, maven needs to be told the kind of project (simple servlet web application or JSF web application with Spring and hibernate or Web application with spring, hibernate and spring MVC etc…). Maven knows the details of the directory structure for each project type through an archetype. So a simple servlet web application will have its own archetype that details how the directory structure of a simple servlet web application looks like.

So to start with execute

mvn archetype:generate

Then Maven will ask you the kind of project you want to create by listing the archetype that it knows about and asking you to select the archetype. Then it wail ask other details about your project (group id, artifact id etc… ) and after all project details are provided, will create the empty project structure for you.