not found: value UADetectorServiceFactory

岁酱吖の 提交于 2019-12-13 19:36:36

问题


On the reference of this question, I try the below code in Scala:

import net.sf.uadetector._
def check = Action { implicit request =>
    println(request.headers)
    var parser = UADetectorServiceFactory.getOnlineUpdatingParser();
    println(parser)
    val agent = parser.parse(request.headers.get("User-Agent").getOrElse(""))
    println(agent)
    val which = agent.getUserAgentType(); // this can be ROBOT, BROWSER, etc.
    println(which)
    Ok(write(Map("result" -> true)))
}

and

libraryDependencies += "net.sf.uadetector" % "uadetector-core" % "0.9.16"

but I am getting an error:

not found: value UADetectorServiceFactory

var parser = UADetectorServiceFactory.getOnlineUpdatingParser();

             ^

Am I missing something?


回答1:


did i am missing something?

Yes, you have imported everything from net.sf.uadetector package, but UADetectorServiceFactory resides in net.sf.uadetector.service

Add

import net.sf.uadetector.service.UADetectorServiceFactory

or

import net.sf.uadetector.service._

And compilation should be okay




回答2:


did i am missing something?

Yes, I got what I am missing, but getUserAgentType is not still working so I used getType() in place of that.

import net.sf.uadetector.service._
import net.sf.uadetector._

def check = Action { implicit request =>
  var parser = UADetectorServiceFactory.getOnlineUpdatingParser()
  println(parser)
  val agent = parser.parse(request.headers.get("User-Agent").getOrElse(""))
  println(agent)
  val which = agent.getType()
  println(which)
  Ok(write(Map("result" -> true)))
}

and needed two library dependencies to run the code above:

  • "net.sf.uadetector" % "uadetector-core" % "0.9.16",

  • "net.sf.uadetector" % "uadetector-resources" % "2013.04",



来源:https://stackoverflow.com/questions/23776617/not-found-value-uadetectorservicefactory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!