1、file--new project 进入如下页面
点击next,
2、进入如下页面
Name:填入项目名称
Location:对应项目文件地址
GroupId、ArtifactId,随意,会在pom文件中见到
Version:默认,会在pom文件中见到
点击 finish,
3、进入如下页面,需要配置pom文件,添加依赖
4、pom文件增加代码
<inceptionYear>2008</inceptionYear>
<properties>
<scala.version>2.11.8</scala.version>
<spark.version>2.3.2</spark.version>
</properties>
<dependencies>
<!-- XGBoost-->
<!-- <dependency>
<groupId>ml.dmlc</groupId>
<artifactId>xgboost4j</artifactId>
<version>0.81</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/xgboost4j-0.81.jar</systemPath>
</dependency>
<dependency>
<groupId>ml.dmlc</groupId>
<artifactId>xgboost4j-spark</artifactId>
<version>0.81</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/xgboost4j-spark-0.81.jar</systemPath>
</dependency>-->
<dependency>
<groupId>ml.dmlc</groupId>
<artifactId>xgboost4j</artifactId>
<version>0.81</version>
</dependency>
<dependency>
<groupId>ml.dmlc</groupId>
<artifactId>xgboost4j-spark</artifactId>
<version>0.81</version>
</dependency>
<!-- LightGBM-->
<dependency>
<groupId>com.microsoft.ml.spark</groupId>
<artifactId>mmlspark_2.11</artifactId>
<version>0.18.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.ml.lightgbm</groupId>
<artifactId>lightgbmlib</artifactId>
<version>2.2.350</version>
</dependency>
<!-- spark依赖-->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>${spark.version}</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-mllib_2.11</artifactId>
<version>${spark.version}</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-catalyst_2.11</artifactId>
<version>${spark.version}</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.11</artifactId>
<version>${spark.version}</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.specs</groupId>
<artifactId>specs</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<!-- <!– flink依赖–>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-scala_2.11</artifactId>
<version>1.7.0</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-streaming-scala_2.11</artifactId>
<version>1.7.0</version>
</dependency>
<dependency>
<groupId>net.minidev</groupId>
<artifactId>json-smart</artifactId>
<version>2.3</version>
<scope>test</scope>
</dependency>-->
</dependencies>
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<scalaVersion>${scala.version}</scalaVersion>
<args>
<arg>-target:jvm-1.8</arg>
</args>
</configuration>
</plugin>
<!-- maven里执行测试用例的插件,不显式配置则用默认配置,默认绑定在test生命周期-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<dependencies>
</dependencies>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<!-- 打包插件:https://www.jianshu.com/p/d44f713b1ec9-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.cntaiping.fintech.business.CarRenewalMain</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
<classesDirectory>
</classesDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
</plugins>
</reporting>
5、说明,依赖中有xgboost等算法的依赖,提前将其开源包添加在lib文件夹中
6、关键步骤,配置maven指向地址,
file-settings-maven
maven home directory: maven在idea-plugins中的位置
user settings file:maven安装文件中配置文件settings的位置
local repository:maven安装文件中repo文件夹的位置
7、点击maven,刷新按钮,pom配置生效
8、准备尝试代码,先建个文件夹
file--project structure
main--new folder 创建Scala文件夹,并标记为sources
9、示例代码,成功
如果想要去掉info信息显示,参见其他文章中描述,resources中增加log4j.properties文件