maven几个知识点的记录

2019-07-09  本文已影响0人  有时右逝

前言

写java这么久,使用maven也较多。由于工具的傻瓜式操作,对很多知识不理解。例如maven便是其中之一。这里总结几个maven使用中的知识点。

环境

mac系统
idea工具

知识点

$ brew search maven
==> Formulae
maven ✔                                                     maven@3.2                                                   homebrew/linuxbrew-core/maven                               homebrew/linuxbrew-core/maven@3.2
maven-completion                                            maven@3.3                                                   homebrew/linuxbrew-core/maven-completion                    homebrew/linuxbrew-core/maven@3.3
maven-shell                                                 maven@3.5                                                   homebrew/linuxbrew-core/maven-shell                         homebrew/linuxbrew-core/maven@3.5

==> Casks
mavensmate

brew install maven

类似jdk,这里需要配置 MAVEN_HOME

$ cat /etc/profile
# System-wide .profile for sh(1)

if [ -x /usr/libexec/path_helper ]; then
    eval `/usr/libexec/path_helper -s`
fi

if [ "${BASH-no}" != "no" ]; then
    [ -r /etc/bashrc ] && . /etc/bashrc
fi

export MAVEN_HOME=/usr/local/Cellar/maven/3.6.0/libexec
export PHANTOMJS_HOME=/usr/local/phantomjs
export PATH=$PATH:$PHANTOMJS_HOME/bin
$ mvn -v
Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-25T02:41:47+08:00)
Maven home: /usr/local/Cellar/maven/3.6.0/libexec
Java version: 1.8.0_131, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "mac os x", version: "10.13.6", arch: "x86_64", family: "mac"
<mirror>  
  <id>alimaven</id>  
  <name>aliyun maven</name>  
  <url>http://maven.aliyun.com/nexus/content/groups/public/</url>;  
  <mirrorOf>central</mirrorOf>          
</mirror>

设置本地仓库路径

 <localRepository>/Users/ft521/Documents/study/tools/maven-350</localRepository>

需要主要的地方,maven有2个配置。上面是全局配置。通常还有一个用户配置。路径位于
/Users/ft521/.m2 里面也存在一个settings.xml 而且优先级比全局的高。

这里我遇到一个坑,idea自带了maven,我忘记修改配置。导致下载依赖包速度非常慢。

因此这里我需要修改idea的maven配置,让它使用我们本地安装的maven。

image.png

maven插件的使用

例如在项目中执行下面的命令。

$ mvn help:effective-settings

打印所有可用的环境变量和Java系统属性

$ mvn help:system

- 使用Maven archetype插件

在一个已经完整的项目中,进入项目文件夹,

$ mvn archetype:create-from-project

等待即可,最后看到一个SUCCESS就表示成功。

 mvn install

此时就可以使用你自定义的模板了。
此时再执行
mvn archetype:generate -DarchetypeCatalog=local
就会出现模板选择,输入数字即可。例如下图。

image.png

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <mainClass>com.insigmaunited.lightai.net.server.LightaiServer</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
上一篇 下一篇

猜你喜欢

热点阅读