One of MAVEN study notes

1. Structure layering in development:

Architecture layering

2, Several main links of the maven build process:

  1. Cleanup : delete previous compilation results and prepare for recompilation
  2. Compile : compile java source program into bytecode file
  3. Test : Test the key points in the project to ensure the correctness of the key points in the iterative development process of the project.
  4. Report : Record and display the test results in a standard format after each test
  5. Packaging : Package a project containing many files into a compressed file for installation or deployment. The java project corresponds to the jar package, and the Web project corresponds to the war package;
  6. Installation : In the Maven environment, it specifically refers to the installation of the packaged result-jar package or war into the local warehouse.
  7. Deployment : Deploy the packaged result to the remote warehouse and deploy the war package to the server to run.

Maven builds the project automatically:

Insert picture description here

3, maven directory structure:Insert picture description here

maven follows: convention> configuration> coding.

4, detailed explanation of pom.xml

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0http://maven.apache.org/xsd/maven-4.0.0.xsd">
     
    	<!-- 模型版本。maven2.0必须是这样写,现在是maven2唯一支持的版本 -->
    	<modelVersion>4.0.0</modelVersion>
     
    	<!-- 公司或者组织的唯一标志,并且配置时生成的路径也是由此生成, 如com.winner.trade,maven会将该项目打成的jar包放本地路径:/com/winner/trade -->
    	<groupId>com.winner.trade</groupId>
     
    	<!-- 本项目的唯一ID,一个groupId下面可能多个项目,就是靠artifactId来区分的 -->
    	<artifactId>trade-core</artifactId>
     
    	<!-- 本项目目前所处的版本号 -->
    	<version>1.0.0-SNAPSHOT</version>
     
    	<!-- 打包的机制,如pom,jar, maven-plugin, ejb, war, ear, rar, par,默认为jar -->
    	<packaging>jar</packaging>
     
    	<!-- 帮助定义构件输出的一些附属构件,附属构件与主构件对应,有时候需要加上classifier才能唯一的确定该构件 不能直接定义项目的classifer,因为附属构件不是项目直接默认生成的,而是由附加的插件帮助生成的 -->
    	<classifier>...</classifier>
     
    	<!-- 定义本项目的依赖关系 -->
    	<dependencies>
     
    		<!-- 每个dependency都对应这一个jar包 -->
    		<dependency>
     
    			<!--一般情况下,maven是通过groupId、artifactId、version这三个元素值(俗称坐标)来检索该构件, 然后引入你的工程。如果别人想引用你现在开发的这个项目(前提是已开发完毕并发布到了远程仓库),--> 
    			<!--就需要在他的pom文件中新建一个dependency节点,将本项目的groupId、artifactId、version写入, maven就会把你上传的jar包下载到他的本地 -->
    			<groupId>com.winner.trade</groupId>
    			<artifactId>trade-test</artifactId>
    			<version>1.0.0-SNAPSHOT</version>
     
    			<!-- maven认为,程序对外部的依赖会随着程序的所处阶段和应用场景而变化,所以maven中的依赖关系有作用域(scope)的限制。 -->
    			<!--scope包含如下的取值:compile(编译范围)、provided(已提供范围)、runtime(运行时范围)、test(测试范围)、system(系统范围) -->
    			<scope>test</scope>
     
    			<!-- 设置指依赖是否可选,默认为false,即子项目默认都继承:为true,则子项目必需显示的引入,与dependencyManagement里定义的依赖类似  -->
    			<optional>false</optional>
     
    			<!-- 屏蔽依赖关系。 比如项目中使用的libA依赖某个库的1.0版,libB依赖某个库的2.0版,现在想统一使用2.0版,就应该屏蔽掉对1.0版的依赖 -->
    			<exclusions>
    				<exclusion>
    					<groupId>org.slf4j</groupId>
    					<artifactId>slf4j-api</artifactId>
    				</exclusion>
    			</exclusions>
     
    		</dependency>
     
    	</dependencies>
     
    	<!-- 为pom定义一些常量,在pom中的其它地方可以直接引用 使用方式 如下 :${file.encoding} -->
    	<properties>
    		<file.encoding>UTF-8</file.encoding>
    		<java.source.version>1.5</java.source.version>
    		<java.target.version>1.5</java.target.version>
    	</properties>
     
    </project>

5. Connect to the private server warehouse

Insert picture description here

6, add WebContent

Insert picture description here

7, Reasons for mvn -install installation failure:

1. Either there is a problem with the path in eclipse and myeclipse;

2. Either the JDK in the POM.xml file does not match;

3. Either the JDK in the setting.xml in the Maven directory and the local .m2 local warehouse directory does not match the native JDK environment;

Of course, these three premises are based on the confirmation that the JDK environment is installed correctly, the environment variables have been configured correctly, and Maven is installed correctly.

Guess you like

Origin blog.csdn.net/qq_43071699/article/details/101376248