18

The following code in the compiler:

abstract class query {def get: Unit => scala.xml.Elem}

gives me the error: "object xml is not a member of package scala"

however when I use scala.xml.Elem in sbt through the command line it works just fine,

how do I fix this?

Thanks in advance

4 Answers 4

48

Scala-XML has been factored out into a separate library as of Scala 2.11, so it is not included in Scala projects by default. To include it in your project via sbt add this dependency:

libraryDependencies += "org.scala-lang.modules" %% "scala-xml" % "1.0.2"
7
  • 1
    I'm using eclipse, where should I place this is my project?
    – zunior
    Jul 3, 2014 at 16:53
  • You didn't specify that in your question. I don't use Eclipse so I'm not sure. If it is still an sbt project within Eclipse, it should go in build.sbt or Build.scala, but other than that I have no idea. Jul 3, 2014 at 16:58
  • How do I know if my project is an sbt project? (Sorry, I'm a huge noob to a lot of this)
    – zunior
    Jul 3, 2014 at 17:19
  • @user3369872 how did you set up your project? Did you just created empty eclipse project, put scala jar on a classpath and written some code? If so, yes, likely your project isn't managed via sbt.
    – om-nom-nom
    Jul 3, 2014 at 18:03
  • @user3369872 You tried that for a Scala 2.10 project, where the XML library is still part of the main Scala library. That would only work in Scala 2.11. Jul 7, 2014 at 18:40
5

(This is for Windows at least)

In Eclipse go to

Project > Properties

On the windows that appears (should be on Java Build Path on the left) choose the "libraries" section and click on "Add External JARs".

Navigate to your installation folder and then to the "lib" folder (usually

C:\Program Files (x86)\scala\lib

or

C:\Program Files\scala\lib

)

and add

scala-xml_2.11-1.0.2

or whatever version you have.

1
  • Where do you download JUST scala, then? Dec 3, 2014 at 17:52
4

Update the dependency

// https://mvnrepository.com/artifact/org.scala-lang.modules/scala-xml_2.12
libraryDependencies += "org.scala-lang.modules" % "scala-xml_2.12" % "1.0.6"
0

I have the same error, I tried lots of ways. Finally, I found it is the Java Loading dependencies order issue. If I move it to the last one. it works fine for me.

I modify it in my IntelliJ Idea: cmd-; Project Settings -- Modules -- Dependencies click + in bottom-left -- 2 Library -- From Maven The solution

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.