I had no luck finding a simple archetype to create a java application that can run by command java -jar [jar_file_name]
, so I created this one. It includes gson 2.8.2
and apache commons-lang3
libraries. A .gitignore
file also inlucded for IntelliJ
.
- Install archetype to local maven repository
# In oneJarApp directory
mvn install
- Create project from local maven archetype
com.tomdeng.archetypes:oneJarApp
from the IDE. For IntelliJ IDEA, a Maven Archetype Catalogs plugin make it easy to load local archetype, simply add /Users/[username]/.m2/repository/archetype-catalog.xml to catalog. - Or, create project by running command:
mvn archetype:generate -DarchetypeCalalog=local
- Add your favorite library to
src/main/resources/archetype-resources/pom.xml
, NOT thepom.xml
in root directory. - Add addtional files in
src/main/resources/META-INF/maven/archetype-metadata.xml
To remove the jar-with-dependencies suffix from the built jar file name, set <finalName>
and <appendAssemblyId>false</appendAssemblyId>
in src/main/resources/archetype-resources/pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<finalName>${project.artifactId}-${project.version}</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
To include .gitignore
file, add <addDefaultExcludes>false</addDefaultExcludes>
to root's pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<!-- Required so that .gitignore gets included in archetypes -->
<!-- See https://issues.apache.org/jira/browse/MRESOURCES-190 -->
<addDefaultExcludes>false</addDefaultExcludes>
</configuration>
To remove Archetypes from IntelliJ IDEA 2020.2 on Mac
rm -rf ~/Library/Caches/JetBrains/IdeaIC2020.2/Maven/Indices
To create an archetype project skeleton structure
mvn archetype:generate
-DarchetypeGroupId=org.apache.maven.archetypes
-DarchetypeArtifactId=maven-archetype-archetype
-DarchetypeVersion=1.4
-DgroupId=<your_groupID>
-DartifactId=<your_artifactId>
-Dversion=<your_artifact_version>