简体   繁体   中英

Create a common library in Play framework

I created 3 subprojects in play: A,B, and common

A and B needs to use common subproject. the code looks like this for the build.sbt:

name := """play"""
organization := "com.play"

version := "1.0-SNAPSHOT"

lazy val common = (project in file("modules/common")).enablePlugins(PlayScala)

lazy val A = (project in file("modules/A")).enablePlugins(PlayScala)
 .dependsOn(common).aggregate(common)
lazy val B= (project in file("modules/B")).enablePlugins(PlayScala)
                .dependsOn(common).aggregate(common)

lazy val root = (project in file(".")).enablePlugins(PlayScala)
            .dependsOn(A).aggregate(A)
            .dependsOn(B).aggregate(B)


scalaVersion := "2.11.11"


libraryDependencies += filters
libraryDependencies += evolutions
libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "2.0.0" % Test

The package system, I follow the documentation in the Play framework which is like "package.moduleName" So, the class in model package in my common subproject has a package name called: "model.common"

Now in subproject A, i want to call the library in the common subproject

I call like this:

import model.common.className

I cannot find it

You can put all the classes inside a top level package. For example for the common project you can put all the classes inside the com.play.common package.

After that you can use the class example (declare in the common project) from the project A using import com.play.common.A .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM