Play Framework中的SBT无法找到org.hibernate依赖项

时间:2013-11-24 16:06:35

标签: java hibernate playframework sbt

当我尝试将Hibernate实现到Play Framework 2应用程序时,它找不到org.hibernate库。

[error] /home/cc/Desktop/eclipses/workspace/muell/app/controllers/HibernateUtil.java:3: error: package org.hibernate does not exist
[error] import org.hibernate.Session;
[error]                     ^
[error] /home/cc/Desktop/eclipses/workspace/muell/app/controllers/HibernateUtil.java:4: error: package org.hibernate does not exist
[error] import org.hibernate.SessionFactory;  
[error]                     ^
[error] /home/cc/Desktop/eclipses/workspace/muell/app/controllers/HibernateUtil.java:5: error: package org.hibernate.cfg does not exist
[error] import org.hibernate.cfg.Configuration;
... and so on ...

以下是build.sbt

name := "muell"

version := "1.0-SNAPSHOT"

libraryDependencies ++= Seq(
  javaJdbc,
  javaEbean,
  cache,
  "mysql" % "mysql-connector-java" % "5.1.18"
)     

val appDependencies = Seq(
    "org.hibernate" %% "hibernate-core" % "4.2.6.Final",
    "org.hibernate" %% "hibernate-entitymanager" % "3.6.9.Final",
    "org.hibernate.javax.persistence" %% "hibernate-jpa-2.0-api" % "1.0.0.Final"
)

play.Project.playJavaSettings

以下是plugins.sbt

// Comment to get more information during initialization
logLevel := Level.Warn

// The Typesafe repository
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
resolvers += "Primary Maven Repository" at "http://repo1.maven.org/maven2/"

// Use the Play sbt plugin for Play projects
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0")

1 个答案:

答案 0 :(得分:3)

这适用于我玩框架2.2.1,我认为它应该在2.2.0中工作,

问题是你是用%%添加scala版本的依赖项,这只适用于java,当然你也可以使用scala。

由于它是一个maven存储库,因此您无需将其作为解析器进行spicify。

这是我的build.sbt的内容:

name := "testHibernate"

version := "1.0-SNAPSHOT"

libraryDependencies ++= Seq(
  jdbc,
  anorm,
  cache,
  "org.hibernate" % "hibernate-core" % "4.3.0.CR1",
  "org.hibernate" % "hibernate-entitymanager" % "4.3.0.CR1",
  "org.hibernate.javax.persistence" % "hibernate-jpa-2.1-api" % "1.0.0.Draft-16"
)     

play.Project.playScalaSettings

如果要更改休眠版本,请转到

http://search.maven.org/#search|ga|1|hibernate并记得用以下内容更改该文件:

"groupId" % "artifactId" % "version"

如果存在改进的scala版本在play框架中解释它:

使用%%

获取正确的Scala版本

如果使用groupID %% artifactID%revision而不是groupID%artifactID%revision(差异是groupID之后的双%%),sbt会将项目的Scala版本添加到工件名称。这只是一个捷径。

我希望它能帮助你!