Can't import scala.xml._

Given the following line of code in a Scala worksheet:

import scala.xml._


this error is generated:

Error: object xml is not a member of package scala


A similar line of code works:
import 
scala.io.Source

Seems basic, but I've been searching for over an hour with no solution!  Have tried or found:

settings at:  Preferences->General->Auto Import
help page at https://www.jetbrains.com/idea/help/managing-imports-in-scala.html

Using IntelliJ IDEA 15.1, scala-sdk-2.11.7

Thanks in advance for any help!

0
4 comments

Found an answer.
https://github.com/scala/scala-xml says: "As of Scala 2.11, this library is a separate jar that can be omitted from Scala projects that do not use XML."
Thus scala-xml needs to be downloaded & included as a dependency:
cmd-; Project Settings -> Modules -> Dependencies
click + in bottom-left -> 2 Library -> From Maven
In the search box of the popup, type the library name "scala-xml" and click the search icon.  A long list of possibilities shows up, and I chose the most recent version corresponding to my version of Scala, 2.11.

2

Thanks, Mark.  This was a big help!

0

You can also use SBT for this.  See https://confluence.jetbrains.com/display/IntelliJIDEA/Getting+Started+with+SBT to get started with SBT.  Once that is setup, all you need to do is update your build.sbt file with no need to update the project settings in Idea.  Fully functional build.sbt file shown below.

name := "AppName"

version := "1.0"

scalaVersion := "2.11.8"

libraryDependencies ++= Seq("org.scala-lang.modules" % "scala-xml_2.11" % "1.0.6")

1

in my case clearing the .bsp and .bloop project-subfolders was needed to get it running, sbt clean was not enough

0

Please sign in to leave a comment.