锁定老帖子 主题:maven 五分钟 cook
该帖已经被评为新手帖
|
|
---|---|
作者 | 正文 |
发表时间:2007-09-21
1 分钟:InstallationMaven is a Java tool, so you must have Java installed in order to proceed First, download Maven and unzip it to your desired installation directory, for example C:\maven in windows, or /usr/local/maven in Linux. After this, add the system variable M2_HOME as well as the $M2_HOME/bin directory to your system path. Type the following in a terminal or command prompt: mvn --version It should print out your installed version of Maven, for example: Maven version: 2.0.4 Depending upon your network setup, you may require extra configuration. Check out the Guide to Configuring Maven if necessary. 2 分钟:Creating a ProjectOn your command line, execute the following maven goal: mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=my-app 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 create goal created a directory with the same name given as the artifactId. Change into that directory. cd my-app Under this directory you will notice the following standard project 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 source code, the src/test/java directory contains the test source, and the pom.xml is the project's Project Object Model, or POM. The POMThe pom.xml file is the core of a project's configuration in Maven. It is a single configuration file that contains the majority of information required to build a project in just the way you want. The POM is huge and can be daunting in its complexity, but it is not necessary to understand all of the intricacies just yet to use it effectively. This project's POM is:
What did I just do?You executed the Maven goal archetype:create , and passed in various parameters to that goal. The prefix archetype is the plugin that contains the goal. If you are familiar with Ant , you may concieve of this as similar to a task. This goal created a simple project based upon an archetype. Suffice it to say for now that a plugin is a collection of goals with a general common purpose. For example the jboss-maven-plugin, whose purpose is "deal with various jboss items". 3分钟:Build the Projectmvn package The command line will print out various actions, and end with the following: ... [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2 seconds [INFO] Finished at: Thu Oct 05 21:16:04 CDT 2006 [INFO] Final Memory: 3M/6M [INFO] ------------------------------------------------------------------------ Unlike the first command executed (archetype:create ) you may notice the second is simply a single word - package . Rather than a goal, this is a phase . A phase is a step in the build lifecycle , which is an ordered sequence of phases. When a phase is given, Maven will execute every phase in the sequence up to and including the one defined. For example, if we execute the compile phase, the phases that actually get executed are:
You may test the newly compiled and packaged JAR with the following command: java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App Which will print the quintessential: Hello World!
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2007-10-26
So cool
可是我的英文太菜还是找中文的看吧 |
|
返回顶楼 | |
发表时间:2007-10-29
Maven是好东西,以前公司的项目用Ant build 一次要2个多小时,用Maven只花了几十分钟。
|
|
返回顶楼 | |
发表时间:2008-06-28
Maven是好东西,以前公司的项目用Ant build 一次要2个多小时,用Maven只花了几十分钟。
2个小时?不会吧,说清楚一点啊 |
|
返回顶楼 | |
发表时间:2008-06-29
cnfree 写道 Maven是好东西,以前公司的项目用Ant build 一次要2个多小时,用Maven只花了几十分钟。
这是扯蛋。。。 maven 似乎没有这样的能力 |
|
返回顶楼 | |
发表时间:2008-08-04
楼主辛苦了,但是你这好象是直接从官方网站上复制下来的哦
|
|
返回顶楼 | |
发表时间:2008-08-20
You are right. It is indeed from Maven official website.But I did this only because it can save me some time to find this article again.
|
|
返回顶楼 | |
发表时间:2008-08-20
cnfree 写道 Maven是好东西,以前公司的项目用Ant build 一次要2个多小时,用Maven只花了几十分钟。
if it's maven's magic,maven can rule the earth soon. but i guess it's a mistake about someone who written the ant-code in your office. |
|
返回顶楼 | |
发表时间:2008-08-22
kimmking 写道 cnfree 写道 Maven是好东西,以前公司的项目用Ant build 一次要2个多小时,用Maven只花了几十分钟。
if it's maven's magic,maven can rule the earth soon. but i guess it's a mistake about someone who written the ant-code in your office. 如果你不是一个老外,在中文论坛里不要用英文。 |
|
返回顶楼 | |
浏览 7837 次