Scala + Java 8 + Eclipse + Maven – Use Scala with Java 8


Like every java developer you must be struggling with using Java and Scala in the same project. So, here is the solution with Eclipse, Maven and Java 8. Just follow these steps:

Step 1: Scala IDE Installation

  • Download Eclipse for JEE and create a workspace.
  • Install Scala IDE for eclipse by going into “Help” -> “Install New Software…”
  • Paste the following link into the “Work with:” field and press enter.
  • You need to check components which are checked in the image below only. (Click on the image to enlarge).

Scala IDE Installation Link:

Eclipse Scala IDE Installation
Eclipse Scala IDE Installation


Step 2: Create a Maven Project

  • Right click in “Project Explorer” -> “New” -> “Other” .
  • In the filter field type “maven” and then select “Maven Project”.
  • Click next again twice now select Aechetype “maven-archetype-quickstart”  and click next.
  • Provide Group Id and Artifact Id and click finish.
  • Follow the image gallery below. (click to enlarge)

Step 3: Update pom.xml to add Maven Compiler Plugin and Scala Plugin & Repos

<project xmlns="" xmlns:xsi=""



		<project .build.sourceEncoding>UTF-8</project>
		<java .version>1.8</java>
		<scala .majorVersion>2.11</scala>
		<scala .minorVersion>8</scala>
		<spark .version>1.6.1</spark>
		<spark .cassandra.connector.version>1.6.0</spark>


			<name>Central Repository</name>
			<name>Scala-tools Maven2 Repository</name>
			<name>Scala-tools Maven2 Repository</name>

					<source />${java.version}


  • Every setting is important in above pom.xml file.
  • Ignore the following maven error shown in the image below. Your project would build totally fine.
Eclipse Maven Scala Plugin Configuration Error
Eclipse Maven Scala Plugin Configuration Error to Ignore

Step 4: Update your project

  • By default your maven project is configured to work with JAVA 5 but we have updated our pom file to enforce maven to work with java 8.
  • Before update your project looks like below:

Eclipse Maven Project 1

  • To update your maven project right click on your project and go to “Maven” -> “Update Project…”.
  • In the dialogue box check “Force Update of Snapshot/Releases” like in the images below.
  • Now your project looks like following:

Eclipse Maven Project Update 3

Step 5: Add a Source Folder for Scala

  • Create a folder in your project as “src/main/scala”
  • Right click on your project go to “Properties” and in Properties select “Java Build Path” like following image (click to enlarge).

Eclipse Maven Scala Source Folder Configuration 1

Step 6: Add Scala Nature to Your Project

  • To Add Scala nature right click on your project go to “Configure” -> “Add Scala Nature” as the image below. This option would be visible if you have installed “Eclipse Scala IDE plugin” as mentioned in Step 1.

Eclipse Maven Scala Natutre 1

  • Now Your project would look like following:

Eclipse Maven Scala Natutre 2

Step 7: Add a new Scala Class and Call it from JAVA file

  • Add a new Scala file in Scala source folder like below
  • I have added a dummy Scala class file as ScalaClass.scala.
package com.harisaltaf

class ScalaClass {

  private val myName: String = "I am a Scala class";

  def getMyName(): String = {

  def dummy = {
    println("I am a dummy method of ScalaClass")
  • And I have called it from my JAVA class
package com.harisaltaf;

public class App {
	public static void main(String[] args) {
		System.out.println("Hello World!");
		ScalaClass sc = new ScalaClass();
  • Run your code from JAVA file because main method is there. You would get following output:

Hello World!
I am a Scala class
I am a dummy method of ScalaClass

Step 8: Debugging

Debugging is as easy as it was in java.

  • Add a break point in method dummy() of ScalaClass.
  • Now click the debug button from JAVA file because main method is there.

Complete Code:

Complete code is attached scala-with-java-maven-and-eclipse.