一、maven下载
1.选择download
2.下载安装,选择安装目录,我的是D:\maven\apache-maven-3.5.4
二、环境变量配置
1.maven下载安装成功后,进入我的电脑--->系统属性--->高级系统设置
2.点击环境变量,然后在系统变量中点击新建变量名为MAVEN_HOME,变量值为刚刚maven安装目录(D:\maven\apache-maven-3.5.4)的变量。
3.在系统变量中找到Path变量,点击编辑按钮, 然后在名为变量值的一栏中最后加上(;%MAVEN_HOME%\bin),记住在最前面有一个分号“ ; ”如果在加分号时已经存在分号,可以不加,但是没有的情况下必须加上。
4.至此maven的环境变量配置完成
5.使用快捷键windows+R检验是否成功
三、IDEA创建Maven项目
1.File ---> settings ---> Bulid..(快捷键 Ctrl + Alt + S) 显示maven默认的配置,可以修改,也可以用默认的。我修改成自己的了。修改后点击ok
2.创建Maven项目
file--->new--->project
3.填写Maven项目坐标值,填完后点击Next
GroupId:一般是域名的反转
ArtifactId:项目名
4.点击Finish完成创建
创建完成后在IDEA右侧显示为下图,在pom.xml中需要进行项目有关jar包的导入,在此发布与学习scala有关的jar包依赖
<!-- 定义一下常量 -->
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<encoding>UTF-8</encoding>
<scala.version>2.11.8</scala.version>
<scala.compat.version>2.11</scala.compat.version>
<akka.version>2.4.17</akka.version>
</properties>
<dependencies>
<!-- 添加scala的依赖 -->
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
<!-- 添加akka的actor依赖 -->
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_${scala.compat.version}</artifactId>
<version>${akka.version}</version>
</dependency>
<!-- 多进程之间的Actor通信 -->
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-remote_${scala.compat.version}</artifactId>
<version>${akka.version}</version>
</dependency>
</dependencies>
<!-- 指定插件-->
<build>
<plugins>
<!-- 指定编译scala的插件 -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.2</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
<configuration>
<args>
<arg>-dependencyfile</arg>
<arg>${project.build.directory}/.scala_dependencies</arg>
</args>
</configuration>
</execution>
</executions>
</plugin>
<!-- maven打包的插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>reference.conf</resource>
</transformer>
<!-- 指定maven方法 -->
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass></mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
导入完成后刷新Maven项目即可。