メイベン
1. MacがMavenをインストールする
1. Mavenをダウンロードし
て、Maven公式Webサイトのダウンロードページを開きます
。http://maven.apache.org/download.cgiダウンロード:apache-maven-3.6.0-bin.tar.gz
ダウンロードしたインストールパッケージを、次のような特定のディレクトリに解凍します。 / Users / xxx / Documents / maven
2.環境変数を設定します
ターミナルターミナルを開き、次のコマンドを入力します。
vim ~/.bash_profile 打开.bash_profile文件,在次文件中添
環境変数を設定するコマンドを追加する
export M2_HOME=/Users/xxx/Documents/maven/apache-maven-3.6.0
export PATH=$PATH:$M2_HOME/bin
追加後に保存して終了し、次のコマンドを実行して構成を有効にします。
source ~/.bash_profile
3.設定が有効かどうかを確認します
入力:mvn -vコマンド
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"
設定は成功しました。
注:
端末が再起動するたびに、zshが〜/ .zshrcファイルをロードし、タスク環境変数が '.zshrc'ファイルで定義されていないため、端末が再起動するたびにソース〜/ .bash_profileが実行されます。
解決策
〜/ .zshrcファイルの最後に、次の行を追加します:source〜/ .bash_profile
2. Maven依存関係管理
maven要求,所有的jar包都放在jar包仓库中,所有的maven项目,都通过jar包仓库来使用jar包.
maven通过jar包坐标来获取jar包.
<groupId>公司</groupId>
<artifactId>项目或jar包名</artifactId>
<version>版本</version>
3. Mavenの倉庫
本地仓库
远程仓库(私服)
中央仓库
4.デフォルトの設定setting.xml
倉庫の場所を設定する
<!--配置本地仓库位置-->
<localRepository>D:\Maven_Repository</localRepository>
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コマンドとライフサイクル
clean //清除所有编译后的资源
compile //编译maven程序
test //不仅编译,而且执行测试(会把所有的测试代码都执行一遍)
package //不仅编译,而且测试,而且打包
install //不仅编译,测试,打包,而且把打包后的程序,放在了本地仓库
deploy //不仅编译,测试,打包,把打包后的程序放在本地仓库,而且会把打包后的程序上传到私服中.
6.ディレクトリ構造
7.プロジェクト設定
ウィンドウを変更する必要があります
8.アイデアを使用してMavenプロジェクトを作成する
不使用骨架.
如果创建的是Java项目,则不需要做任何修改.
如果创建的是web项目:
1.需要在pom.xml文件中,添加一个<packaging>war</packaging>
2.在main文件夹下,创建一个webapp文件夹.
3.在Project Structure界面中,点击 目标模块-》web-》加号-》生成web.xml文件
4.把生成的"WEB-INF"文件夹,拖入webapp文件夹中.
9.中国語の文字化けした問題に対処するためのIdea MavenのVMOption構成(対応できない可能性があります)
-DarchetypeCatalog=internal -Dfile.encoding=GBK
10. 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.一般的に使用される依存関係
<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.一般的に使用されるtomcat7プラグインのホットビルドテンプレートと一般的に使用される依存ホットキーを設定する
設定->ライブ検索->ラインテンプレート->テンプレートグループの設定->テンプレートの作成と設定はxmlファイルのみをサポート