Is there a common webapp in a project with multiple Java / scala modules?

I use SBT / scala, but this question can also apply to Maven / Java projects since SBT is based on Maven frameworks.

I would like to create a multiprocessor application with a common webapp deployment. How should I structure my project in Maven / SBT, and is there a webapp available on the package step?

Structure

sharedlibrary/
   webapp/
module1
module2
module3

so when I pack module 1 (which depends on sharedlibrary), I would like webapp to be included in the final war file. Webapp will have code that loads the correct core class Module1 based on which server it was running on. Is this possible in simple form in maven / sbt?

+3
source share
2 answers

sbt, . .

1) "project" , *.

2) "project/Build.scala" . destPath . Google App Engine war .

import sbt._
import Keys._

object MyBuild extends Build {
  lazy val copyDependencies = TaskKey[Unit]("copy-dependencies")
  def copyDepTask = copyDependencies <<= {
    (dependencyClasspath in Runtime, baseDirectory) map { (dep, bp) => 
    for (attrSrcPath <- dep) {
      val srcPath = attrSrcPath.data
      println(srcPath);
      if (!srcPath.isDirectory) {
        val destPath = bp / "war/WEB-INF/lib" / srcPath.getName
        IO.copyFile(srcPath, destPath, preserveLastModified=true)
      }
      else {
        val destPath = bp / "war/WEB-INF/classes/"
        IO.copyDirectory(srcPath, destPath, preserveLastModified=true)
      }
    }
  }

  lazy val webapp = Project("webapp", file("sharedlibrary/webapp"))
  lazy val module1 = Project("module1", file("module1"),
      settings = Project.defaultSettings ++ Seq(copyDepTask)
    ) dependsOn(webapp)
  lazy val module2 = Project("module2", file("module2"),
      settings = Project.defaultSettings ++ Seq(copyDepTask)
    ) dependsOn(webapp)
  lazy val module3 = Project("module3", file("module3"),
      settings = Project.defaultSettings ++ Seq(copyDepTask)
    ) dependsOn(webapp)
}

3) sbt, project module1 copy-dependencies, sbt webapp module1 war/WEB-INF/classes war/WEB-INF/lib.

Google App Engine appspot, , -.

+1

All Articles