作者:mysrain3 | 来源:互联网 | 2023-09-16 12:21
篇首语:本文由编程笔记#小编为大家整理,主要介绍了idea spark 创建maven项目相关的知识,希望对你有一定的参考价值。
.file->new -> project
2.选择Maven,添加模板创建项目
![](https://img6.php1.cn/3cdc5/c3e4/c5a/d13b04a4ed16e2ce.jpeg)
3.填写Groupid、ArtifactId信息。GroupId:com.公司名称/个人名称.项目名;ArtifactId:子项目名称
![](https://img6.php1.cn/3cdc5/c3e4/c5a/a54b67a698b49b09.jpeg)
4.选择本地安装的maven和setting.xml文件
![](https://img6.php1.cn/3cdc5/c3e4/c5a/5714a131240feecc.jpeg)
5.工程名称和路径
![](https://img6.php1.cn/3cdc5/c3e4/c5a/b34a9858bc6f9ce8.jpeg)
6.点击Finish. 修改pom.xml如下:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0modelVersion>
<groupId>com.rzx.nsgroupId>
<artifactId>sparktestartifactId>
<version>1.0-SNAPSHOTversion>
<inceptionYear>2008inceptionYear>
<properties>
<project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
<spark.version>1.6.0spark.version>
<scala.version>2.10scala.version>
<hadoop.version>2.6.0hadoop.version>
properties>
<dependencies>
<dependency>
<groupId>org.apache.sparkgroupId>
<artifactId>spark-core_${scala.version}artifactId>
<version>${spark.version}version>
dependency>
<dependency>
<groupId>org.apache.sparkgroupId>
<artifactId>spark-sql_${scala.version}artifactId>
<version>${spark.version}version>
dependency>
<dependency>
<groupId>org.apache.sparkgroupId>
<artifactId>spark-hive_${scala.version}artifactId>
<version>${spark.version}version>
dependency>
<dependency>
<groupId>org.apache.sparkgroupId>
<artifactId>spark-streaming_${scala.version}artifactId>
<version>${spark.version}version>
dependency>
<dependency>
<groupId>org.apache.hadoopgroupId>
<artifactId>hadoop-clientartifactId>
<version>2.6.0version>
dependency>
<dependency>
<groupId>org.apache.sparkgroupId>
<artifactId>spark-streaming-kafka_${scala.version}artifactId>
<version>${spark.version}version>
dependency>
<dependency>
<groupId>mysqlgroupId>
<artifactId>mysql-connector-javaartifactId>
<version>5.1.39version>
dependency>
dependencies>
<repositories>
<repository>
<id>centralid>
<name>Maven Repository Switchboardname>
<layout>defaultlayout>
<url>http://repo2.maven.org/maven2url>
<snapshots>
<enabled>falseenabled>
snapshots>
repository>
repositories>
<build>
<sourceDirectory>src/main/scalasourceDirectory>
<plugins>
<plugin>
<groupId>org.scala-toolsgroupId>
<artifactId>maven-scala-pluginartifactId>
<executions>
<execution>
<goals>
<goal>compilegoal>
<goal>testCompilegoal>
goals>
execution>
executions>
<configuration>
<scalaVersion>2.10.6scalaVersion>
<args>
<arg>-target:jvm-1.5arg>
args>
configuration>
plugin>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-shade-pluginartifactId>
<version>2.2version>
<configuration>
<createDependencyReducedPom>truecreateDependencyReducedPom>
configuration>
<executions>
<execution>
<phase>packagephase>
<goals>
<goal>shadegoal>
goals>
<configuration>
<artifactSet>
<includes>
<include>*:*include>
includes>
artifactSet>
<filters>
<filter>
<artifact>*:*artifact>
<excludes>
<exclude>META-INF/*.SFexclude>
<exclude>META-INF/*.DSAexclude>
<exclude>META-INF/*.RSAexclude>
excludes>
filter>
filters>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>reference.confresource>
transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">
<resource>log4j.propertiesresource>
transformer>
transformers>
configuration>
execution>
executions>
plugin>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-resources-pluginartifactId>
<version>3.0.2version>
<executions>
<execution>
<id>copy-resourcesid>
<phase>validatephase>
<goals>
<goal>copy-resourcesgoal>
goals>
<configuration>
<outputDirectory>${basedir}/target/classesoutputDirectory>
<resources>
<resource>
<directory>src/resourcesdirectory>
<filtering>falsefiltering>
resource>
resources>
configuration>
execution>
executions>
plugin>
plugins>
build>
project>
7.点击Import.导入jar包
![](https://img6.php1.cn/3cdc5/c3e4/c5a/997887ca074d644b.jpeg)
8.如果无法创建scala文件. 则File->project Structure...Global Libraries 重新导下scala-sdk包即可(删除再添加,本人的环境可能有问题,正常不需要此操作)
![](https://img6.php1.cn/3cdc5/c3e4/c5a/dc32d2cd6e93e3e2.jpeg)
9.com.rzx.ns目录下. 右键New->scala class 创建scala文件. 环境ok可以开发了。。。