Last active
December 11, 2015 08:59
-
-
Save baijian/4577251 to your computer and use it in GitHub Desktop.
maven is a good thing to manage java project...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
before we start to create a project using maven, | |
maybe we should set a proxy..... | |
we can use maven archetype plugin to help us to | |
create a maven project , you can see archtype | |
as a existing template. | |
>>mvn archetype:generate | |
then terminal will prompt you to choose a number(choose a template), | |
because there are a lot of choices, so you can use filter to | |
filter some like input "quick", then you can see | |
maven-archetype-quickstart,maybe its number is 19, | |
so you input 19 Enter. | |
Then it will let you select a version, | |
maybe you select the default latest version, just Enter. | |
Then you need to set some properties: | |
* groupId: com.sysdev.learn(the unique group id specifies | |
where the project is located hierachically in a maven repository, | |
so you can allow similar projects into similar groups) | |
* artifactId: learn-helloworld(just think it as a project name) | |
* version: 1.0 | |
* package: com.sysdev.learn.helloworld | |
Then it will ask you if confirm these configuration, | |
if yes just input Y, then your project is created. | |
Then you want to see your project in a tree format(if you have installed tree), | |
just input: >>tree learn-helloworld. | |
In a word, creat a project from an archetype involves three steps: | |
* the selection of the archetype | |
* the configuration of the archetype | |
* the effective creation of the project from the selected infomation | |
ok, at last let us input all the command once: | |
mvn archetype:create(old,default create quick-start maven project) | |
-DgroupId=com.sysdev.learn.helloworld -DartifactId=learn-helloworld | |
You think it is over? | |
=== | |
ofcourse not, you will want to develop the project in elipse, so you should import the project to the eclipse, | |
so cd your-project, use maven eclipse:eslipse goal | |
>>mvn eclipse:eslipse | |
run abvoe command, it just create two files .classpath and .project, which is used for eclipse. | |
Then just use eslipse IDE to new a project from existing sourcecode. | |
ofcourse there are some other ways to import an existing maven project to eclipse. | |
=== | |
After you develop your project for a while, you want to test your project, of course use the test phase of maven build lifecycle. | |
>>mvn test | |
you input command above, it will execute the test phase and all the steps of the maven build lifecycle up to the test phase. | |
=== | |
OK, you have finish you project, so you have to build your project. | |
>>mvn package | |
so it will base on pom.xml begin to package...... | |
=== | |
After you package your project, then ou can install it to your local repository for your other project to use. | |
>>mvn install | |
===An example to create a web application project with Maven=== | |
>>mvn archetype:generate | |
>>-DgroupId=com.baijian.web.helloworld | |
>>-DartifactId=helloworld | |
>>-DarchetypeArtifactId=maven-archetype-webapp | |
>>-DinteractiveMode=false | |
>>tree ./helloworld | |
>>mvn eclipse:eclipse -Dwtpversion=2.0 | |
```-Dwtpversion=2.0``` argument is made to let it | |
be a web project, then import it to eclipse | |
IDE, it will be as a web project. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment