【问题标题】:What is intellij's build process for play applicationsIntellij 的游戏应用程序构建过程是什么
【发布时间】:2018-01-17 13:46:56
【问题描述】:

我想了解IntelliJ 如何构建play 应用程序。在我看来,这一切都像是一个黑匣子。我可以使用默认的Play2Run 配置构建默认应用程序。它似乎使用了Build 脚本。我怎么能看到Build 做了什么?

我想更改构建过程并复制一些不属于项目目录的文件,因此需要从系统上的其他位置复制它们。我能够使用File->Project Structure 选项将这些文件包含在工作区中,但这并不会使这些文件成为构建过程的一部分。有人告诉我,在部署应用程序之前,我需要从外部目录复制这些文件作为构建过程的一部分。但是不知道去哪里找。

您可以参考我的两个相关问题以了解我想要实现的目标

unable to include external files in a project

Include external files (not libraries) in a project in Intellij

【问题讨论】:

标签: intellij-idea playframework-2.0


【解决方案1】:

我能够解决我的问题。我不知道IntelliJ 是如何编译play 项目的,但我注意到如果所需的文件放在公用文件夹中,那么IntelliJ 将部署这些文件。

1) 我在build.sbt创建了一个sbt任务

/* task to Copy files in ../common/css and ../common/javascripts in public/stylesheet/common and public/javascripts/common*/
val copyCommonFilesInPublicKey = taskKey[Int]("Copies files in ../common/css and ../common/javascripts in public/stylesheet/common and public/javascripts/common")

/*
the xcopy command is used to copy all the files and folders [/s] newer than those already copied [/d], including empty folders [/e]. 'common' folder in destination is assumed to be a 
directory [/i] and xcopy will not seek permission to overwrite files [/y]
*/
copyCommonFilesInPublicKey := {
    val copyCSS = Process(Seq("xcopy", "/i", "/s","/y","/d","/e","..\\common\\css", "public\\stylesheets\\common\\")).!<
    println(s"copy CSS returned ${copyCSS}")
    val copyJS = Process(Seq("xcopy", "/i","/s", "/y","/d","/e","..\\common\\javascripts", "public\\javascripts\\common\\")).!<
    println(s"copy JS returned ${copyJS}")
    copyJS
}

2) 我在 IntelliJ 中创建了一个新的 sbt 任务,它将使用在步骤 1 中创建的任务 Run -&gt; Edit Configurations -&gt; + (on top left) -&gt; sbt Task。我把它命名为move files to public,在Tasks中给了copyCommonFilesInPublicKey

3) 我编辑了默认的Play2Run 配置。 Edit Configuration -&gt; select play2Run -&gt; + (on right side this time) -&gt; select Run Another Conguration -&gt; selected moves file to public (created in step 2) -&gt; moved this new configuration above Play2Run built

现在公共文件被移动到公共文件夹,我可以从那里在代码中访问它们,如下所示:

<link rel="stylesheet" media="screen" href="@routes.Assets.versioned("stylesheets/common/css-reset.css")">
<link rel="stylesheet" media="screen" href="@routes.Assets.versioned("stylesheets/common/common-styles.css")">
<link rel="stylesheet" media="screen" href="@routes.Assets.versioned("stylesheets/common/vendor/bootstrap/bootstrap.css")">

【讨论】:

    猜你喜欢
    • 2018-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多