簡體   English   中英

將MySql添加到playframework 2.2.1

[英]Adding MySql to playframework 2.2.1

我正在嘗試使用play框架連接到mysql數據庫。 從我自己的搜索,我知道我需要在某處添加此行:

"mysql" % "mysql-connector-java" % "5.1.18"

但是,在每個文檔/類似的問題中,它表示此行要么進入Build.scala文件,要么進入build.sbt文件,我沒有這些文件。 當我創建我的應用程序(作為一個Java應用程序)時,它只給了我一個build.propertiesplugins.sbt ,它們位於項目文件夾中。

有誰知道如何添加這條線? 我需要創建其中一個文件嗎?

我的build.properties文件:

 sbt.version=0.13.0

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/"

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

更新:添加后

addSbtPlugin("mysql" % "mysql-connector-java" % "5.1.18")到我的插件文件:

在此輸入圖像描述

您需要在sbt文件中添加行。

libraryDependencies ++= Seq(
 jdbc,
 anorm,
 cache,
 "mysql" % "mysql-connector-java" % "5.1.18"
)

之后通過取消注釋更改為您的application.config

#
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://127.0.0.1:3306/test"
db.default.user="root"
db.default.password=""

在plugin.sbt中添加此行

addSbtPlugin("mysql" % "mysql-connector-java" % "5.1.18")

你有沒有這里的構建文件$YOUR_PROJECT_NAME\\project\\Build.scala

plugins.sbt應該包含這個:

// The Typesafe repository 
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"

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

在Build.scala中你應該有這個:

  val appDependencies = Seq(
    // Add your project dependencies here,
    jdbc,
    anorm,
    "mysql" % "mysql-connector-java" % "5.1.18"
  )

老實說,最好是運行play可執行文件並創建項目而不是IDEA。

cmd是: $ play new myAppName

然后使用IDEA的sbt插件,或者如果你有IDEA 13,你可以使用SBT導入項目。

https://github.com/mpeltonen/sbt-idea

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM