Maven Basics

来源:互联网 发布:怎么做淘宝网页 编辑:程序博客网 时间:2024/05/17 10:56

I assumed that you have correctly installed and configured Java Development Kit.

First, you should download apache maven from this page: https://maven.apache.org/download.cgi.

There are several kinds of files for you. I choosed the binary zip archive, and unzipped the file under the directory: D:\Program Files\apache-maven-3.3.9:


Then right click on your computer as below, and choose the menu "属性".


Then go through the following steps, when you are at step 4, type the path of bin in your unzipped maven directory (for me, it is "D:\Program Files\apache-maven-3.3.9\bin") to the end of value.


Save and exit, open cmd.exe and type "mvn -v" to test whether you have installed and configured maven correctly.

Create a folder for test purpose: D:\java_test.

In cmd, change to the directory: D:\java_test which you just created. Type:

mvn archetype:generate -DgroupId=com.mycompany.helloworld -DartifactId=helloworld -Dpackage=com.mycompany.helloworld -Dversion=1.0-SNAPSHOT

Wait, and when you are asked to "Choose a number", type106.

Wait, and when you are asked to confirm Yes, type enter button.

Wait until the process is over, and refresh your D:\java_test directory, you will see a new folder named "helloworld" whose directory structure is as below:


Open App.java and AppTest.java, in top lines of these two file, revise package name to be com.mycompany.helloworld as below:



Open pom.xml and revise values of groupId, artifactId and version as below:


Then in cmd, change directory to be under the helloworld directory, and then type mvn package as bellow:


You can then find a new folder created:


In cmd, type:

java -cp target/helloworld-1.0-SNAPSHOT.jar com.mycompany.helloworld.App

and you will see:


Yes, "Hello World!" was printed to the screen.

Back to the file App.java, and you will know where this output is from:


That's all, bye.

by Yakima Teng on February 24, 2016 in Shanghai.

0 0
原创粉丝点击