使用one-jarjava
1) build.sbt文件,修改成如下內容git
import com.github.retronym.SbtOneJar._ oneJarSettings //上面是導入的onejar name := "xxxx" version := "1.0" scalaVersion := "2.11.7" //這個是須要運行的主類或者object mainClass in oneJar := Some("com.test.MainServer")
2) project\plugins.sbtgithub
//添加插件依賴 addSbtPlugin("com.github.retronym" % "sbt-onejar" % "0.7")
3) project\Build.scalajson
import com.github.retronym.SbtOneJar import sbt._ import sbt.Keys._ object Build extends Build { scalaVersion := "2.11.7" // 添加onejar設置 def standardSettings = Seq( exportJars := true ) // defaultSettings 自定義的,一些依賴或者參數,具體項目具體定義,也能夠去掉 lazy val project = Project("xxxx", file("."), settings = defaultSettings ++ standardSettings ++ SbtOneJar.oneJarSettings ) }
4) 而後使用命令行進入當前代碼的目錄,啓動sbt,執行one-jar測試
> one-jar [info] Updating {file:/E:/scalaProject/xxxxx/}xxxxxx... Waiting for lock on C:\Users\xxxxxx\.ivy2\.sbt.ivy.lock to be available... [info] Resolving jline#jline;2.12.1 ... [info] Done updating. [info] Packaging E:\scalaProject\xxxxxx\target\scala-2.11\xxxxxxx_2.11-1.0-one-jar.jar ... [info] Done packaging. [success] Total time: 10 s, completed 2016-xx-xx 11:41:00
最後查看一下這個jar包,因爲當前項目依賴比較多,文件比較大,有27M左右,ui
測試運行一下插件
java -jar E:\scalaProject\xxxxxx\target\scala-2.11\xxxxxxx_2.11-1.0-one-jar.jar命令行
很好,代碼啓動了.scala