First, the basic concept of Maven
Major service project for building Java-based platform, dependent on information management and project management.
1.1, the project to build
Project build process, including clean-up project [Project] → [compile] → [] → [test project to generate test reports] → [Project] → [package] these steps to deploy the project, complete these six steps is a project build process .
1.2, dependency management
Refers to an interdependence between dependent jar package, such as when we build a framework for the development of Struts2, there are bare struts2-core-2.3.16.3.jar this jar package is not enough, struts2-core-2.3.16.3.jar but also on other jar package, used to rely on the jar package management refers to the use Maven to manage the project, Maven management approach is "automatically download jar package needed for the project, the unified management of dependencies between the jar package."
1.3, Maven benefits
Maven used appointments, java source code, which must be placed in the directory, compiled java code and which must be placed under the directories that have a clear agreement.
Maven every action has a life cycle, for example, can automatically execute mvn install compile, test, package and so build process
Only need to define a pom.xml, then the source code in the default directory, Maven to help us deal with other things
Use Maven project build can be highly automated, dependency management (this is the biggest advantage of using Maven), warehouse management.
Two, Maven commonly used commands
eclipse inherits the environment, remove mvn.
This is mainly the use of the eclipse maven, therefore only a part of the command, after finishing down for easy access.
1. Generate Clear Eclipse project structure:
mvn the Eclipse: the Eclipse
mvn the Eclipse: Clean
2. Clean (compiled contents delete target directory)
mvn Clean
3. Run the test
mvn test
4. Compile the project
mvn compile
Package the release , (generation target directory, compile, test code, generate test reports, generated jar / war file)
mvn Package Penalty for
6. upload jar package , (performed in the integration or release environment, copies of the final version of the package to the remote repository, so that other developers or projects can be shared)
mvn deploy
Attachment:
mvn deploy:deploy-file -DgroupId=com.xy.Oracle -DartifactId=ojdbc14 -Dversion=10.2.0.4.0 -Dpackaging=jar -Dfile=E:\ojdbc14.jar -Durl=http://localhost:9090/nexus-2.2-01/content/repositories/thirdparty/ -DrepositoryId=thirdparty
DgroupId and DartifactId constitute the jar wrapped in pom.xml coordinates project is to rely on these two attributes positioning. Himself a name is required.
Dfile represents the absolute path of the need to upload a jar.
Position Durl PW warehouse, open nexus -> repositories menu, you can see the path.
Represents id DrepositoryId server, the configuration nexus can be seen.
Dversion indicates the version information, how to get a jar package accurate version of it?
Unzip the package, you will find a file called MANIFEST.MF, the file will have version information of the package.
For example Manifest-Version: 1.0 can know the version of the package.
After a successful upload, click the nexus interface 3rd party warehouse can see this package.
7. Jar to publish third-party local library
mvn install:install-file -DgroupId=com -DartifactId=client -Dversion=0.1.0 -Dpackaging=jar -Dfile=d:\client-0.1.0.jar
8. test only without the compiler
mvn test -skipping compile
9. The test does not compile
mvn skipping test-compile
10. Skip test package
mvn package -Dmaven.test.skip = ture
Reproduced in: https: //www.jianshu.com/p/c763006d227e