Java Play中的配置 - ebean和postgresql

时间:2017-04-09 18:59:33

标签: java playframework ebean

我无法正常运行Play Framework项目。我想使用postgresql db和ebean,但配置有问题,我不断收到编译错误。你能看看并检查一下可能是什么原因吗?

我的build.sbt文件:

import play.sbt.PlayJava

name := """play-java-intro"""

version := "1.0-SNAPSHOT"

lazy val root = (project in file(".")).enablePlugins(PlayJava)

scalaVersion := "2.11.7"

libraryDependencies ++= Seq(
  "org.postgresql" % "postgresql" % "9.4-1206-jdbc42",
  "javax.persistence" % "persistence-api" % "1.0.2"
)

fork in run := true

plugins.sbt:

// The Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.13")

// Web plugins
addSbtPlugin("com.typesafe.sbt" % "sbt-coffeescript" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-less" % "1.1.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-jshint" % "1.0.4")
addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.8")
addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.1.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-mocha" % "1.1.0")
addSbtPlugin("org.irundaia.sbt" % "sbt-sassify" % "1.4.6")
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "3.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-play-enhancer" % "1.1.0")

我的模特课:

package models;
import java.util.*;
import com.avaje.ebean.Finder;
import com.avaje.ebean.Model;
import play.data.format.*;
import play.data.validation.*;

import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class Person extends Model {

    @Id
    private Long id;

    @Constraints.Required
    public String name;
    @Constraints.Required
    public String surname;

    @Formats.DateTime(pattern="dd/MM/yyyy")
    public Date date;

    public static Finder<Long,Person> finder = new Finder<Long, Person>(Person.class);
}

错误信息:

[error] com.avaje.ebean.Finder
[error] /home/guras/play-java-intro/app/models/Person.java:6: package com.avaje.ebean does not exist
[error] /home/guras/play-java-intro/app/models/Person.java:7: package com.avaje.ebean does not exist
[error] com.avaje.ebean.Model
[error] /home/guras/play-java-intro/app/models/Person.java:15: cannot find symbol
[error]   symbol: class Model
[error] Model
[error] /home/guras/play-java-intro/app/models/Person.java:28: cannot find symbol
[error]   symbol:   class Finder
[error]   location: class models.Person
[error] Finder
[error] /home/guras/play-java-intro/app/models/Person.java:28: cannot find symbol
[error]   symbol:   class Finder
[error]   location: class models.Person
[error] Finder


[info] play.forkrun.protocol.Serializers$playExceptionPickler$$anon$1: Compilation error[package com.avaje.ebean does not exist]
[info]  at play.forkrun.protocol.Serializers$playExceptionPickler$.unpickle(Serializers.scala:159)
[info]  at play.forkrun.protocol.Serializers$PlayRunsupportReloaderCompileFailureUnpickler$macro$56$2$.unpickle(Serializers.scala:175)
[info]  at play.forkrun.protocol.Serializers$PlayRunsupportReloaderCompileResultUnpickler$macro$66$2$.unpickle(Serializers.scala:181)
[info]  at scala.pickling.Unpickler$class.unpickleEntry(Pickler.scala:79)
[info]  at play.forkrun.protocol.Serializers$PlayRunsupportReloaderCompileResultUnpickler$macro$66$2$.unpickleEntry(Serializers.scala:181)
[info]  at scala.pickling.functions$.unpickle(functions.scala:11)
[info]  at sbt.serialization.JsonValue$$anonfun$parse$1.apply(SerializedValue.scala:104)
[info]  at scala.util.Try$.apply(Try.scala:192)
[info]  at sbt.serialization.JsonValue.parse(SerializedValue.scala:104)
[info]  at sbt.protocol.BuildValue.value(Values.scala:11)

2 个答案:

答案 0 :(得分:0)

您必须将ebean jar作为依赖项添加到类路径中。导入失败,因为您没有在类路径中包含这些包的依赖项jar。 您可以在Maven centeral repository here

中找到罐子

答案 1 :(得分:0)

关于你plugins.sbt

addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "3.1.0")

在你的build.sbt上 lazy val root = (project in file(".")).enablePlugins(PlayJava, PlayEbean)

libraryDependencies ++= Seq(
  javaJdbc,
  javaCore,
  "org.postgresql" % "postgresql" % "9.4.1212"
)

您必须启用ebean插件才能使用play框架。