Simple Maven archetype for Java development.
JavaArchetype is predefined workspace structure, containing preconfigured [pom.xml][pom], .gitignore and example project App.java with example test AppTest.java.
project ├── pom.xml ├── .gitignore ├── src (Project sources and resources) │ └── (project package) | └── App.java (Example project) ├── tests (Project tests) │ └── AppTest.java (Example test) └── build (! created after compile !) ├── classes (Compiled project) | └─ (project package) | └─ App.class (Example project, compiled) ├── tests (Compiled tests) | └─ AppTest.class (Example test, compiled) └─ project.jar (Example project, packaged)
- Download the latest source code with git (
git clone https://github.com/matesssaks/JavaArchetype
) or as zip. - Go to the folder with main pom.xml. Example:
cd JavaArchetype
. - Install to your local Maven repository with
mvn install
.
For proper usage you need to know:
- group ID: cz.matesssaks.archetype
- artifact ID: JavaArchetype
- version: (! version installed on your PC !) — Latest is 1.4.2
To generate project workspace with this archetype in your directory use:
mvn archetype:generate -DarchetypeArtifactId="JavaArchetype" -DarchetypeGroupId="cz.matesssaks.archetype" -DarchetypeVersion="1.4.2"
The new folder, containing workspace, with name of artifactId you specified will be created.
Installed archetype can be found in VS CODE using extension: Maven for Java.
After you successfully created your new workspace, go configure [pom.xml][pom], you can add your web page URL, set project description, specify project license, add developer list, configure project, add dependencies and more. 😃
For some basic project configuration checkout <properties>
tag in your workspace's [pom.xml][pom].
Available properties:
- project.build.sourceEncoding (Default: UTF-8) — Project encoding
- mainClass (Default: [package].App) — Project's main class. See Code Execution.
- args (Default: one two three) — Arguments supplied to program when ran, separated with space. See Code Execution.
- exec.java (Default: java) — Path/command to java binary, used by
exec:exec
, see Code Execution. - skipTests (Default: false) — Skip tests. Tests will still compile, but will not be runned.
- maven.compiler.source (Default: 7, disabled) —
-source
argument for java compiler (source compatibility with specified release, use with JDK 8 and lower) - maven.compiler.target (Default: 7, disabled) —
-target
argument for java compiler (minimum targeted JVM version that can run compiled classes, use with JDK 8 and lower) - maven.compiler.release (Default: 7) —
-release
argument for java compiler (replaces-source
,-target
and-bootclasspath
arguments, better version cross-compilation, ! available only in JDK 9 and beyond !) - maven.compiler.showDeprecation (Default: false) — Show source locations of deprecated APIs
- maven.compiler.showWarnings (Default: false) — Show compilation warnings
- maven.jar.addMavenDescriptor (Default: true) — Include project's pom.xml and pom.properties file in exported JAR.
- maven.jar.addClasspath (Default: true) — Add required runtime dependencies to JAR Manifest's Classpath.
- maven.jar.classpathPrefix (Default: lib) — Path to directory containing required runtime dependencies, relative to JAR location. Leave empty if dependencies are in same folder as JAR.
- maven.jar.mainClass (Default: ${mainClass}) — Location of main class in JAR, needed when creating executable JAR. Leave empty if you don't want JAR executable (e.g. library).
- maven.jar.addDefaultImplementationEntries (Default: false) — Add these entries to JAR Manifest:
Implementation-Title: ${project.name} Implementation-Version: ${project.version} Implementation-Vendor: ${project.organization.name}
- maven.jar.addDefaultSpecificationEntries (Default: false) — Add these entries to JAR Manifest:
Specification-Title: ${project.name} Specification-Version: ${project.artifact.selectedVersion.majorVersion}.${project.artifact.selectedVersion.minorVersion} Specification-Vendor: ${project.organization.name}
- maven.jar.addBuildEnvironmentEntries (Default: false) — Add these entries to JAR Manifest:
Build-Tool: ${maven.build.version} Build-Jdk: ${java.version} (${java.vendor}) Build-Os: ${os.name} (${os.version}; (${os.arch})
All properties can be quickly overridden on command line with -D(property)
argument.
Example: mvn compile -Dmaven.compiler.showDeprecation=true
If you want to run your code there are several options:
mvn exec:java
— Execute main class from compiled classes inbuild/classes
directory. Libraries are loaded from local Maven repository on your computer.mvn compile
is needed to be run before. To attach debugger to program, usemvnDebug
, example:mvnDebug exec:java
.mvn exec:exec@jar
— Execute main class from jar file inbuild/
directory. Libraries are loaded frombuild\lib
directory. See Library copying process.mvn package
is needed to be run before. Doesn't work withmvnDebug
.mvn exec:exec@jar-nolib
— Execute main class from jar file inbuild/
directory. No libraries are loaded.mvn package
is needed to be run before. Doesn't work withmvnDebug
.
To make Maven less annoying run mvn
or mvnDebug
with -q
(quiet) parameter. Example: mvn -q exec:java
If you want run mvnDebug
on different port (default is 8000), you must locate and edit mvnDebug
script on your PC or obtain new at Maven's GitHub.
All libraries needed by program in runtime are copied to build/lib
folder. This copying process is bound to Maven's package phase (See Maven Build Lifecycle).
Copyright 2020 matesssaks
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Help us improve this project, see CONTRIBUTING.md for more info.