Maven
1. Mac installs Maven
1. Download Maven to
open the Maven official website download page: http://maven.apache.org/download.cgi
download: apache-maven-3.6.0-bin.tar.gz
decompress the downloaded installation package to a certain directory, such as: / Users / xxx / Documents / maven
2. Configure environment variables
Open the terminal terminel and enter the following command:
vim ~/.bash_profile 打开.bash_profile文件,在次文件中添
Add commands to set environment variables
export M2_HOME=/Users/xxx/Documents/maven/apache-maven-3.6.0
export PATH=$PATH:$M2_HOME/bin
Save and exit after adding, execute the following command to make the configuration take effect:
source ~/.bash_profile
3. Check whether the configuration takes effect
Input: mvn -v command
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /Users/thor/Documents/maven/apache-maven-3.6.3
Java version: 11.0.2, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home
Default locale: zh_CN_#Hans, platform encoding: UTF-8
OS name: "mac os x", version: "10.15.3", arch: "x86_64", family: "mac"
The configuration is successful.
Note:
Every time the terminal restarts, it is found that zsh loads the ~ / .zshrc file, and the task environment variables are not defined in the '.zshrc' file, which will cause the source ~ / .bash_profile to be executed every time the terminal is restarted.
Solution
At the end of the ~ / .zshrc file, add a line: source ~ / .bash_profile
2. Maven dependency management
maven要求,所有的jar包都放在jar包仓库中,所有的maven项目,都通过jar包仓库来使用jar包.
maven通过jar包坐标来获取jar包.
<groupId>公司</groupId>
<artifactId>项目或jar包名</artifactId>
<version>版本</version>
3. Maven's warehouse
本地仓库
远程仓库(私服)
中央仓库
4. The default configuration setting.xml
Set warehouse location
<!--配置本地仓库位置-->
<localRepository>D:\Maven_Repository</localRepository>
Set up Alibaba Cloud Private Server
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
<mirror>
<id>central</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
5. Maven commands and life cycle
clean //清除所有编译后的资源
compile //编译maven程序
test //不仅编译,而且执行测试(会把所有的测试代码都执行一遍)
package //不仅编译,而且测试,而且打包
install //不仅编译,测试,打包,而且把打包后的程序,放在了本地仓库
deploy //不仅编译,测试,打包,把打包后的程序放在本地仓库,而且会把打包后的程序上传到私服中.
6. Directory structure
7. Project settings
windows need to be changed
8. Use idea to create maven project
不使用骨架.
如果创建的是Java项目,则不需要做任何修改.
如果创建的是web项目:
1.需要在pom.xml文件中,添加一个<packaging>war</packaging>
2.在main文件夹下,创建一个webapp文件夹.
3.在Project Structure界面中,点击 目标模块-》web-》加号-》生成web.xml文件
4.把生成的"WEB-INF"文件夹,拖入webapp文件夹中.
9. VMOption configuration of Idea Maven to deal with Chinese garbled problem (may not be able to deal with it
-DarchetypeCatalog=internal -Dfile.encoding=GBK
10. Handle the conflict between servlet plug-in and project servlet plug-in in tomcat
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
<!--tomcat插件-->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<!--uriEncoding:用来解决Tomcat7插件的get请求的中文乱码问题-->
<uriEncoding>UTF-8</uriEncoding>
<!--port:端口号-->
<port>8080</port>
<!--path:设置虚拟路径-->
<path>/day24</path>
</configuration>
</plugin>
</plugins>
</build>
11. Commonly used dependencies
<dependencies>
<!--druid连接池-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.9</version>
</dependency>
<!--mysql-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.26</version>
<scope>runtime</scope>
</dependency>
<!--jdbcTemplate-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<!--junit-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!--servlet-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<!--jsp-->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.0</version>
<scope>provided</scope>
</dependency>
<!--jstl-->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!--beanUtils-->
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.2</version>
<scope>compile</scope>
</dependency>
<!--jackson-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.3.3</version>
</dependency>
<!--jedis-->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.7.0</version>
</dependency>
</dependencies>
12. Set template commonly used tomcat7 plug-in hot build and commonly used dependent hotkeys
settings-> search live-> line Templates-> set template groups-> write templates and settings only support xml files