Scala – Visual Studio Code on Ubuntu No.83

How to execute Scala application in Visual Studio Code on Ubuntu is shown in this blog.

▼1. Run Scala code in Visual Studio Code on Ubuntu

Scala or PySpark application on Apache Spark cluster is generally used. how to deploy Scala application in Visual Studio Code on Ubuntu is helpful for the deployment of application on Spark cluster.


▼2. Prerequisites

2-1. Install Ubuntu 20.04.2 LTS

https://releases.ubuntu.com/20.04/

2-2. Install Visual Studio Code

https://code.visualstudio.com/docs/setup/linux

sudo snap install --classic code

2-3. Install JDK

Install Java 8 openjdk x64 of zulu

mkdir  -p /usr/lib/jvm/
cd /usr/lib/jvm/
sudo wget https://cdn.azul.com/zulu/bin/zulu8.66.0.15-ca-jdk8.0.352-linux_x64.tar.gz
sudo tar -xzvf zulu8.66.0.15-ca-jdk8.0.352-linux_x64.tar.gz
sudo mv zulu8.66.0.15-ca-jdk8.0.352-linux_x64 java-8-openjdk-linux_x64

Set environment variables for the installed JDK

Adding below at the end of ~/.bashrc (vi ~/.bashrc)

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-x64/

Checking if $JAVA_HOME is correctly updated.

echo $JAVA_HOME

2-4. Install Maven

Apache Kafka Word Count – Java No.44 “2-3. Installing Apache Maven”

2-5. Install Scala (Metals) release version

InstallScalaMetals


▼3. Run Scala application to print Hello World

3-1. Create a project by clicking Metals

ClickMetalsIcon
ClickNewScalaProject

3-2. Use template of Scala3

UseScala3.g8Template

3-3. Set the path of a Scala project

In this case, the project will be created in scala3_tmp folder under scalacode folder.

ChosePath
ConfirmPath
CreateFolder

3-4. Choose No about opening a new window

StayAWindow

3-5. import build

ImportBuild

3-6. Start Debugging

Run the existing Main.scala to print Hello World.

StartDebugging
RunScalaHelloWorld

4. Preference

  1. https://marketplace.visualstudio.com/items?itemName=scalameta.metals
  2. https://scalameta.org/metals/docs/editors/vscode/
  3. YouTube Setting up Scala for Data Science in VS Code and IntelliJ

That’s all. Have a nice day ahead !!!

Leave a Reply

Your email address will not be published. Required fields are marked *