maven real - reading notes

Chapter One: Maven Introduction

1. This book is a domestic community recognized expert Xu Xiaobin wrote the book based on maven3.0 written, maven is very good modeling tool, maven build to maximize the elimination of duplication, abstract build life, he still one advantage, helping us build a standardized process, with maven, all project build commands are simple and consistent, he was a dependency management tools, and project information management tool that provides a central repository, we can help build automatic download.

2. Make the other modeling tools, make Makefile is a script file named drive, the file using your own syntax definitions, the basic components are Rules, and every rule also includes a target (Target), dependent (prerequisite ) and command (command), make a series of targets and will depend on the entire process of building together, while taking advantage of the local command do the actual behavior of each target, the power of Make is that he can take advantage of the local command of all systems, especially unix and linux systems, feature-rich, powerful command can help Make efficient completion of tasks, Make drawback to bind themselves together and operating system, use the Make, difficult to build cross-platform, Makefile syntax is also a problem because Make a build fails is often difficult to find because of a space or tab mistake.

3. Other Ant (Another Neat Tool) modeling tools, he first used to build the famous tomcat, Ant can be seen as a java version of Make, because the use of java, it is cross-platform, and, like Make, Ant is procedural, developers specify each goal, and the goal to complete the task to be performed for each target, developers need to write repeat this process, Maven are declarative, the project to build the various stages of the process and procedures the work required by the plug-in implementation, and most plug-ins are readily available, developers only need to affirm the basic elements of the project, Maven executed a built-in, complete the build process, to a large extent eliminate duplication. Ant does not rely on management, for a long time Ant had to rely on manual management, management can now rely on the aid of lvy, Maven dependency management not only built, are more likely to have a java open source packages around the world the most central repository, Maven users, no configuration can directly enjoy.

Chapter II: Maven Installation and Configuration

1.windows installation maven

First, you need to check whether the installed java environment, run cmd command, echo "% JAVA_HOME%" java-version; javac -version

1. JDK installation, the system environment variable added -----> Variable name: JAVA_HOME, variable value: D: \ jdk1.8.0_91; add the CLASSPATH variable names, variable values:;.% JAVA_HOME% \ lib \ dt.jar ;% JAVA_HOME% \ lib \ tools.jar; then add in the path marked red configuration, you can also add edit this article, remember to verify that is before adding; the end of the, if not the first to add; later, add your own java path, then; end.

2.Maven installation

Download Path: http://maven.apache.org/download.cgi    , apache-maven-3.6.1-bin.zip   extraction path D: \ developTools \

 

 Configuration environment variable: variable name: MAVEN_HOME: variable value: D: \ developTools \ apache-maven-3.1.0, add in the path

2.linux installation maven

Download Path: http://maven.apache.org/download.cgi    ,   the Apache Maven-3.6.1-bin.tar.gz-   extract to a local directory

We have now created a good apache-maven-3.0, although the direct use of the directory configuration environment variable can be configured to use maven, but the recommended practice is next to the directory where you installed parallel to create a symbolic link to facilitate future upgrades ln -s apache-maven -> apache-maven-3.0, a second step of setting the environment variables MAVEN_HOME symbolic link apache-maven, and the bin in the installation directory / folder is added to the variable path in the system; Generally, these needs two rows login shell commands are added to the system, edit ~ / .bashrc file, adding two lines, each time a terminal starts, the configuration may be performed automatically. The following command

export MAVEN_HOME=/home/local/bin/apache-maven

export PATH:$PATH:$MAVEN_HOME/bin

Maven test whether the installation was successful: echo $ MAVEN_HOME mvn -v

Upgrade maven: maven Suppose we now need to upgrade to version 3.1 maven, Unzip the package to a previous version of the parallel directory, and then update the symbolic link to the version 3.1 directory on the line ln -s apache-maven-3.1 / apache-maven

3. Analysis of the installation directory

maven directory structure

bin:该目录包含了mvn运行的脚本,这些脚本来配置java命令,准备好classpath和相关的java系统属性,然后执行java命令,其中mvn是linux的shell脚本,mvn,bat是windows平台的bat脚本,在命令行中输入一条mvn命令时,实际上是调用这些脚本,该目录还包含了mvnDebug和mvnDebug.bat两个文件,两种有何区别,mvnDebug比mvn多了一条MAVEN_DEBUG_OPTS配置,其作用是运行Maven时,开启debug模式,以便调试maven本身,该目录还包含了m2.conf文件,这是classworlds的配置文件,后面会介绍classworlds。

boot:该目录只包含一个文件,该文件为plexus-classworlds-2.2.3.jar,plexus-classworlds是一个类加载器框架,相对于java类加载器,他提供了更丰富的语法以方便配置。

conf:该目录包含了一个非常重要的setting.xml,直接修改该文件,能在机器上全局的定制maven的行为,一般情况下,我们会复制一份,然后在修改。

lib:该目录包含了所有maven运行期间需要的java类库,maven本身是分模块开发的,因此用户还可以看到maven-core-3.0,maven-model-3.0之类的文件,此外,还包含了一些maven用到的第三方依赖库,common-cli-1.2.jar,google-collection-1.0.jar等

4.设置http代理

公司基于安全因素考虑,要求你通过使用安全认证的代理访问因特网,这种情况下,就需要为maven配置http代理,才能让他正常访问外部仓库。

在setting.conf文件中,proxies中可以有多个proxy元素,如果申明了多个proxy元素,则默认第一个被激活的proxy会生效,这里申明了一个id为optional的代理,active的值为true,表示激活该代理,protocol表示使用的代理协议,这里是http,host和port为主机名和端口,username和password设置认证信息,nonProxyHosts用来指定哪些主机名不需要代理,可以使用“|“来分割多个主机名,改配置也可以使用通配符,如*。google.com,表示所有以google.com结尾的域名访问都不需要通过代理。 

 

Guess you like

Origin www.cnblogs.com/hejj-bk/p/11415630.html