Windows IDEA 项目(Scala+Sbt、Scala+Maven)创建与远程部署到Linux(远程部署其它项目也适用)

一、scala+sbt

注:sbt为创建项目时IDEA自动安装的
前提:先安装Scala插件

1. scala-sbt项目创建:
  • File => New => project
    在这里插入图片描述

  • Next在这里插入图片描述

    • 为避免后续部署到Linux运行出现问题,选择Scala版本时注意Linux安装的Spart版本是基于哪个Scala版本构建的

    Note that, Spark 2.x is pre-built with Scala 2.11 except version 2.4.2, which is pre-built with Scala 2.12. Spark 3.0+ is pre-built with Scala 2.12.

在这里插入图片描述

  • Finish,等待"dump project structure from sbt",即把sbt所需要的项目结构从远程服务器拉取到本地
    在这里插入图片描述
    • 完成后,scala文件夹会变为蓝色,然后可以开始创建.scala文件
2. 编辑build.sbt
  • 基于你所需要编写的程序,编辑build.sbt,比如添加
libraryDependencies += "org.apache.spark" %% "spark-core" % "3.0.1"
  • 添加后会出现红色框的部分,不建议直接refresh,因为下载资源比较慢
    在这里插入图片描述
    • 解决方法(参考网页),仅供参考(本人下载spark-sql用了11分钟,不知道是否是解决了,毕竟11分钟时间挺长)
      在这里插入图片描述

      • C:/user(用户)/xxx/.sbt
      • 创建repositories,内容为
        [repositories]
        local
        huaweicloud-maven: https://repo.huaweicloud.com/repository/maven/
        aliyun-nexus: https://maven.aliyun.com/nexus/content/groups/public/
        jcenter: https://jcenter.bintray.com/
        maven-central: https://repo1.maven.org/maven2/
        typesafe-ivy-releases: https://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly
        sbt-plugin-repo: https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
        
      • IDEA:File => Setting在这里插入图片描述
        • VM parameters添加:-Dsbt.override.build.repos=true
        • Apply,Ok

附:
在这里插入图片描述

二、scala+maven

  • File => New => project
    在这里插入图片描述
  • Next
    在这里插入图片描述
  • Finish
  • 工程名称上右键 => Add Framework Surport => Scala (同样,选择Scala版本时注意Linux安装的Spart版本是基于哪个Scala版本构建的)

Add Framework Surport 找不到 Scala:参考博客

  • 配置依赖
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>SampleScalaMaven</artifactId>
    <version>1.0-SNAPSHOT</version>

    <repositories>
        <repository>
            <id>jboss</id>
            <name>JBoss Repository</name>
            <url>http://repository.jboss.com/maven2/</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency> <!-- Spark dependency -->
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-core_2.12</artifactId>
            <version>3.0.1</version>
        </dependency>
    </dependencies>
    <build>
        <sourceDirectory>src/main/scala</sourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.scala-tools</groupId>
                <artifactId>maven-scala-plugin</artifactId>
                <version>2.15.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <scalaVersion>2.12.10</scalaVersion>
                    <args>
                        <arg>-target:jvm-1.8</arg>
                    </args>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

注:以下这部分依赖不能少
在这里插入图片描述
少了会出现的问题:当使用Maven打包项目为jar并上传到Linux运行的使用,会出现Failed to load class SencondarySort
在这里插入图片描述

  • Refresh => 完成(Down)

  • 附:IDEA 自带 Maven 配置国内源

    • 打开"IDEA安装目录(如:IntelliJ IDEA 2020.1)\plugins\maven\lib\maven3\conf\settings.xml",找到mirrors,编辑如下: 在这里插入图片描述
<mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <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>alimaven</id>
		<name>aliyun maven</name>
		<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
		<mirrorOf>central</mirrorOf>
	 </mirror>
</mirrors>

三、远程部署到Linux

  • Tools => Deployment => Configuration
    在这里插入图片描述
  • + => SFTP
    在这里插入图片描述
  • SSH Configuration
    在这里插入图片描述
  • 填写相关SSH配置信息
    在这里插入图片描述
  • Test Connection
    在这里插入图片描述
  • Ok => Ok
  • Root path
    在这里插入图片描述
  • Mapprings => Deployment path(相对于Linux用户主目录的,即上图/home/hadoop)
    在这里插入图片描述
    • 部署路径为:/home/hadoop/Myapp/sample_scala_maven
  • Test Connection
    在这里插入图片描述
  • Ok => Ok
  • Tools => Option => 把本地已改变的文件上传到默认服务器 => Always => Ok
    在这里插入图片描述
  • 个人建议:打包完成之后,手动Upload整个项目,避免远程jar包未更新
    在这里插入图片描述

参考:window+idea搭建远程调试spark环境

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值