Splitting the Web App😃
In the "Working with sub-projects" series, our next topic is Splitting the web app. Here, we will discuss the steps like build config, project structure, etc.

A Play app can depend on another Play app as it is simply a regular sbt project with a default setup. Depending on whether the project is a Java or Scala project, you can turn any sub-module into a Play app by including the PlayJava or PlayScala plugins in its corresponding build.sbt file.
Splitting the Route File
If the user wants to create a robust, reusable Multi module Play app, then they can split the route file into smaller pieces.
To split the route file, we have to follow the below process:
Build Configuration
Follow the configuration in the build.sbt folder.
name := "myproject"
lazy val admin = (project in file("modules/admin")).enablePlugins(PlayScala)
lazy val main = (project in file("."))
.enablePlugins(PlayScala).dependsOn(admin).aggregate(admin)
And do the same in modules/admin/build.sbt:
name := "myadmin"
libraryDependencies ++= Seq(
"mysql" % "mysql-connector-java" % "5.1.41",
jdbc,
anorm
)
Project Structure
The next step is to learn the project structure. Follow the below map for this:
build.sbt
app
└ controllers
└ models
└ views
conf
└ application.conf
└ routes
modules
└ admin
└ build.sbt
└ conf
└ admin.routes
└ app
└ controllers
└ models
└ views
project
└ build.properties
└ plugins.sbt
The name of the Configuration and route file must be unique in the whole project. "admin.routes" is the name of the admin route file. Using a specific set of settings in development mode for a sub-project in the build file would be better. For example: PlayKeys.devSettings += ("play.http.router", "admin.Routes").
Use the below command in the conf/routes file:
GET /index controllers.HomeController.index()
-> /admin admin.Routes
GET /assets/*file controllers.Assets.at(path="/public", file)
Similarly for the modules/admin/conf/admin.routes:
GET /index controllers.admin.HomeController.index()
GET /assets/*file controllers.Assets.at(path="/public/lib/myadmin", file)
Assets and controller classes
It is necessary that all Assets and controller classes should be defined in the controllers.admin package.
Make a note that all the codes are in Java language.
For Assets:
package controllers.admin;
import play.api.mvc.*;
import controllers.AssetsMetadata;
import play.api.http.HttpErrorHandler;
import javax.inject.Inject;
public class Assets extends controllers.Assets {
@Inject
public Assets(HttpErrorHandler errorHandler, AssetsMetadata meta) {
super(errorHandler, meta);
}
public Action<AnyContent> at(String path, String file) {
boolean aggressiveCaching = true;
return super.at(path, file, aggressiveCaching);
}
}
For Controller:
package controllers.admin;
import play.mvc.Controller;
import play.mvc.Result;
public class HomeController extends Controller {
public Result index() {
return ok("admin");
}
}
Reverse Routing 🔁
We can reverse the routing in both Assets and Controller in the admin.
For Assets:
controllers.admin.routes.Assets.at("...")
For Controller:
controllers.admin.routes.HomeController.index
Sharing common codes and variables🔗🤝🏻

We will now discuss how to share codes and variables in the "Working with sub-projects" series.
You can put these in a Scala file in the project directory of the root project if you want your sub-projects and root projects to share specific standard settings or code. For instance, project/Common.scala could have the following:
import sbt._
import Keys._
object Common {
val settings: Seq[Setting[_]] = Seq(
organization := "com.example",
version := "1.2.3-SNAPSHOT"
)
val fooDependency = "com.foo" %% "foo" % "2.4"
}
Advantages of using the Play framework😯
Using the Play framework has a lot of advantages like:
- High productivity web development
- Reactive programming
- Satisfies enterprise needs
- Scalable
- Large team application
- Security
- Traditional data access
Frequently Asked Questions💡

What is an activator in the Play framework?
A new Play app can be made with the activator command. You can choose a template in Activator to base your new app. These templates are available for plain Play projects under the names play-scala for Scala-based Play apps and play-java for Java-based Play apps.
What is the Play framework in Scala?
Scala & Java dev can create web apps quickly and easily with Play Framework. Play's architecture is lightweight, stateless, and suitable for the web. Play, based on Akka, gives highly scalable apps predictable and low resource consumption like CPU, memory, and threads.
What is sbt in the Play framework?
sbt files specify project settings. Also, as stated in the sbt manual, you can create your own unique custom parameters for your project. Knowing the sbt settings, in particular, is helpful.
Conclusion🎉
We have discussed the topic of Working with sub-projects. We have seen how to add a library, share common codes and variables, and steps to split the web app.
We hope this blog has helped you enhance your knowledge of "Working with sub-projects." If you want to learn more, check out our articles Aggregating Reverse Routers, Anatomy of a Play application, Coordinated Shutdown, and many more on our platform Coding Ninjas Studio.
But suppose you have just started your learning process and are looking for questions from tech giants like Amazon, Microsoft, Uber, etc. In that case, you must look at the problems, interview experiences, and interview bundle for placement preparations.
However, you may consider our paid courses to give your career an edge over others!
Happy Learning!
