Reading: Maven – Maven in 5 Minutes
first, download Maven and follow the initiation instructions. After that, type the stick to in a terminal or in a control prompt : Maven is a Java cock, so you must have Java installed in order to proceed .
Creating a Project
You need somewhere for your project to reside. Create a directory somewhere and start a husk in that directory. On your command line, execute the follow Maven finish :
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false
If you have just installed Maven, it may take a while on the first run. This is because Maven is downloading the most recent artifacts (plugin jars and other files) into your local repository. You may also need to execute the command a couple of times before it succeeds. This is because the remote server may time out before your downloads are complete. Don’t worry, there are ways to fix that.
You will notice that the generate goal created a directory with the like appoint given as the artifactId. Change into that directory.
cd my-app
Under this directory you will notice the trace standard plan structure .
my-app |-- pom.xml `-- src |-- main | `-- java | `-- com | `-- mycompany | `-- app | `-- App.java `-- test `-- java `-- com `-- mycompany `-- app `-- AppTest.java
The src/main/java
directory contains the project reservoir code, the src/test/java
directory contains the test generator, and the pom.xml
file is the project ‘s Project Object Model, or POM .
The POM
The pom.xml
file is the core of a project ‘s shape in Maven. It is a single configuration file that contains the majority of information required to build a project in good the way you want. The POM is huge and can be daunting in its complexity, but it is not necessity to understand all of the intricacies equitable even to use it effectively. This project ‘s POM is :
4.0.0 com.mycompany.app my-app 1.0-SNAPSHOT 1.7 1.7 junit junit 4.12 test
What did I just do?
You executed the Maven goal archetype:generate, and passed in diverse parameters to that goal. The prefix archetype is the plugin that provides the goal. If you are companion with Ant, you may conceive of this as like to a undertaking. This archetype:generate goal created a bare project based upon a maven-archetype-quickstart original. Suffice it to say for now that a plugin is a collection of goals with a general coarse purpose. For case the jboss-maven-plugin, whose function is “ deal with assorted jboss items ” .
Build the Project
mvn package
The command line will print out assorted actions, and end with the trace :
Read more: How to use Google Keep for web research
... [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.953 s [INFO] Finished at: 2019-11-24T13:05:10+01:00 [INFO] ------------------------------------------------------------------------
Unlike the inaugural command executed ( archetype:generate ), the second is just a single word – package. Rather than a goal, this is a phase. A phase is a tone in the physique lifecycle, which is an coherent sequence of phases. When a phase is given, Maven executes every phase in the sequence up to and including the one defined. For example, if you execute the compile phase, the phases that actually get executed are :
- validate
- generate-sources
- process-sources
- generate-resources
- process-resources
- compile
You may test the newly compiled and packaged JAR with the adopt command :
java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App
Which will print the quintessential :
Hello World!