Provides the scaffolding for building and packaging a Spring 3 (Java) web-application with SBT.
Scala Java JavaScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Build a Spring 3 Web-Application with SBT

Yes, it is possible.


I can haz no more project and build definitions in XML.

I like writing my build files in Scala, and the SBT community provides a number of very useful open-source plugins that make building and packaging web-applications a breeze.

Further, all of the existing SBT managed web-application examples are centered around Scala. This makes complete sense — SBT is the goto tool for compiling and building Scala based projects. However, it's often overlooked that SBT does support the compilation and building of Java based projects as well.

So, consider this a proof-of-concept that SBT can, and does, work with Java based web-applications.

Building and Running

This web-application example and its dependencies are built and managed using SBT 0.12.2.

To clone and build this project, you must have SBT installed and configured on your computer.

The spring3-sbt Build.scala file is highly customized to build and package this Java web-application.

To build, clone the repository.

#~> git clone git://

Run SBT from within your newly cloned spring3-sbt directory.

#~> cd spring3-sbt
#~/spring3-sbt> sbt

You will see a spring3-sbt SBT prompt once all dependencies are resolved and the project is loaded.

In SBT, run container:start to start the local Servlet container. By default the server listens on port 8080.

spring3-sbt:0.0.2> container:start
[info] jetty-8.0.4.v20111024
[info] started o.e.j.w.WebAppContext{/,[file:~/spring3-sbt/src/main/webapp/]}
[info] Initializing Spring root WebApplicationContext
10/27 10:41:33 INFO  [pool-6-thread-2] o.s.w.s.DispatcherServlet -
    FrameworkServlet 'spring3': initialization completed in 60 ms
[info] Started SelectChannelConnector@ STARTING
[success] Total time: 2 s, completed Oct 27, 2012 10:41:33 AM

In your nearest web-browser, visit http://localhost:8080 and you should see a typical "It works!" page. This placeholder pages is a rendering of src/main/webapp/WEB-INF/jsp/index.jsp in the spring3-sbt source tree.

To stop the development server, run container:stop.

See the xsbt-web-plugin wiki for all of the gory details on managing the development servlet container from SBT.

In SBT, run package to build a deployable WAR for your favorite Servlet container.

spring3-sbt:0.0.2> package
[info] Compiling 6 Java sources to ~/spring3-sbt/target/classes...
[info] Packaging ~/spring3-sbt/dist/spring3-sbt-0.0.2.jar ...
[info] Done packaging.
[info] Packaging ~/spring3-sbt/dist/spring3-sbt-0.0.2.war ...
[info] Done packaging.
[success] Total time: 8 s, completed Oct 27, 2012 10:47:38 AM

Note the resulting WAR is placed into the spring3-sbt/dist directory.

Server Compatibility

The WAR produced by this project is confirmed to work with the following containers:

Servlet Engine Container  
Servlet 3.0 Tomcat 7
Jetty 8
Jetty 9 Untested
Servlet 2.5 Tomcat 6
Jetty 7

NOTE: may work with other containers, such as Weblogic or Websphere, but these have not been tested.


Naturally, this artifact depends on spring-web 3.2.1.RELEASE, and spring-webmvc 3.2.1.RELEASE.

It also firmly depends on my common package of utility classes kolich-common, and shared Spring 3 core classes kolich-spring.


Copyright (c) 2012 Mark S. Kolich

All code in this project is freely available for use and redistribution under the MIT License.

See LICENSE for details.