简体   繁体   English

将Java库导入Scala sbt项目

[英]Import Java library to Scala sbt project

I'm trying to use import guava library in SBT project (play framework), but can't compile my code 我正在尝试在SBT项目中使用import guava库(播放框架),但无法编译我的代码

import com.google.common.net.InternetDomainName

class MyClass(link: String) {
  private val domains = {
    val host = new URL(link).getHost
    val domainName = InternetDomainName.from(host)
    domainName.topPrivateDomain().name()
  }
}

I get compilation error 我收到编译错误

object google is not a member of package com

Can anyone explain, what is the problem? 任何人都可以解释一下,问题是什么?

Have you added the guava library as a library dependency to your build.sbt file? 您是否已将guava库作为库依赖项添加到build.sbt文件中? You can find that file in the project's root directory. 您可以在项目的根目录中找到该文件。 There you can add the dependency to the guava library: 在那里你可以添加依赖项到guava库:

libraryDependencies ++= Seq(
  "com.google.guava" % "guava" % "17.0",
  // other dependencies separated by commas
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM