Skip to content

nathan-ca/maven-archetype-java-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maven Archetype: Java Stand-alone Application

This archetype could be used to generate new stand-alone java application source tree and a customized maven build process.

In the new Java project, maven pom.xml and assembly script were integrated together to bundle all java library, execution script, release notes, etc, into a zip file for easy distribution and deployment. The bundle could be generated by simple 'mvn package' command. Unlike spring boot project which build a fat jar, this project structure keep dependant jar libraries separately under lib sub-folder.

Setup and Demo

Follow these steps to quickly install this archetype and create a sample maven project to see generated files. Supose you are in an empty directory: ~/work

Setup: Clone this project to your computer and install the archetype
# pwd
~/work
# git clone https://github.com/nathan-ca/maven-archetype-java-app.git
# cd maven-archetype-java-app
# mvn install archetype:update-local-catalog
The archetype was installed in your local maven repository.
Demo: Create a sample maven project (non-interactive mode)
# pwd
~/work
# mvn archetype:generate -DarchetypeGroupId=com.github.nathan-ca -DarchetypeArtifactId=archetype-java-app -DarchetypeVersion=1.0.0 -DgroupId=com.github -DartifactId=sample -DinteractiveMode=false
# cd sample
# mvn package

A new maven project sample was generated in the work directory and the 'mvn package' command packaged compiled binary and resources into a sample.zip file under target dir.

This sample.zip file could be distributed easily. End user just unzip the sample.zip and run the script to launch the java application.

The directory structure in sample.zip:

sample/             : top directory
sample/release.txt  : your release document
sample/run-app.cmd  : execution script to launch Java application 
sample/run-app.sh   : execution script to launch Java application 
sample/sample.jar   : compiled jar from your source
sample/lib/*.jar    : dependant jar files

Maven Interactive Command

# mvn archetype:generate \
  -DarchetypeGroupId=com.github.nathan-ca -DarchetypeArtifactId=archetype-java-app \
  -DarchetypeVersion=1.0.0

Customization on New Project

Customize and update the following files in your new project:

release.txt: write your own release note
src\bin\run-app.*: write your own Java launch command
src\main\resources\log4j2.xml: customize the log4j2 behavior

Customize the src\assembly\bin.xml file for your own content in zip file.

Known Issue

When creating new project, the following warning messages will be generated by maven:

[WARNING] Don't override file ......
[WARNING] CP Don't override file ......

The fix should be in archetype-metadata.xml file but I don't know how to. Let me know if you found the solution.