Follow the steps below to create a simple Maven project and run a few Maven targets
1. Create project catalog
C: / daven
2. Create a storage directory of Java source code
C: / Daven / SRC / Java
3. Create the same directory structure as the package structure
C: / daven / src / java / smartsoft / daven
4. Create a simple class box
file name:
C: /daven/src/java/smartsoft/daven/box.java
content:
Public class box {
PRIVATE INT Length;
Private Int Width;
Public Box (int LENGTH, INT WIDTH) {
THIS.LENGTH = Length;
THIS.WIDTH = Width;
}
Public int getarea () {
Return Length * width;
}
}
5. Create a project object model
file name:
C: /DAVEN/Project.xml
content
$ {Basedir} / src / java
sourceDirectory>
build>
provject>
Now run a Maven built-in target, Java: Compile. Open a command prompt, switch to the project directory, and type:
Maven Java: Compile
You will see the following output:
C: / daven>
Maven Java: Compile
Java: Prepare-FileSystem:
Java: Compile:
[echo] compling to c: / daven / target / classes
Build Successful
Total Time: 33 SECONDS
Note that the Java: Compile target has a prerequisite, Java: Prepare-FileSystem destination. Mavel is similar to the depends of Ant.
Now you check your file system, you will see that Maven generates a directory structure for saving class files for you.
C: / daven
SRC
Java
Smartsoft
Daven
Box.java
Target
Classes
Smartsoft
Daven
Box.class
TEST-CLASSES
Test-Reports
Use the other targets to type at the command prompt:
Maven Jar
You will see the following:
C: / daven> maven jar
Java: Prepare-FileSystem:
Java: Compile:
[echo] compling to c: / daven / target / classes
Java: Jar-Resources:
Test: prepare-filesystem:
Test: Test-Resources:
Test: Compile:
[echo] no test source files to compile
Test: Test:
[echo] no tests to run
Build Successful
Total Time: 6 seconds
Note that there are many prerequisites for JAR objectives.
Java: Prepare-FileSystem
Java: Compile
Java: Jar-Resources
Test: prepare-filesystem
Test: Test-Resources
Test: Compile
Test: Test
Maven also creates a file named Daven-1.0.jar in the target directory. Its name comes from the ID and CurrentVersion elements in the project object model file. Now execute the Clean target. Type: Java Clean
You will get this output:
C: / daven>
Maven Clean
Clean: Clean:
[delete] deleding Directory C: / Daven / Target
Build Successful
Total Time: 7 seconds
If you check your file system again, you will be deleted in the birth of the Target directory.
Understanding
You have already running three goals Java: Compile, Jar.clean. Although Goal in Maven is equivalent to Target in Ant, you don't have to create your own goals, Maven has provided Most the goals you need. To write this When Wen, Maven already has 312 Goal. (Translator Note: You can use the Maven -g command to view all installation plugins and targets)
Keep in mind that Maven's goal is organized into the plugin. In fact, in the Maven's homepage, "a small core like artificial satellite" (original: "Small Core That Works with a Satellite of Plug-Ins ") Most Maven features in the form of plug-ins. The plug-in provides a prefix of the target name. For example, Java: Compile will call the Java plug-in compile target. If you do not have any target name, then the plugin will be called the default Target. For example, Maven Jar will call the default target of the JAR plugin.