GlenPeterson
GlenPeterson

Reputation: 5216

SBT (Simple Build Tool): Change the build target "classes" directory

Question

For Java web applications, if you put classes where the web server expects them on your development machine, it can save you the step of packaging and redeploying your web-app every time you compile. It also simplifies things to have the development and deployment directory structure the same. Tomcat's Standard Directory Layout is:

WEB-INF/
WEB-INF/classes
WEB-INF/lib

But SBT wants to put all classes in:

target/scala-2.10/classes

How do I tell sbt to put classes in WEB-INF/classes instead?

Background

So far, I've been using SBT just for unit tests and I run it from WEB-INF instead of my project's root directory and don't worry about where it throws the classes because tests don't need to be deployed. I guess I could wrap SBT in a batch file that cd's to WEB-INF, then cd's back when done, but that seems a little kludgey.

How do people work around this issue? I could delete WEB-INF/classes then copy target/scala-2.10/classes to it after each build, but that might eliminate some of the benefits of incremental/minimal compilation that SBT offers.

Extra Credit...

I'm not sure if this is part of a new question, but it falls under "using SBT to build a Java web app" so I'll include it: Tools like log4j, Struts, proxool, and Hibernate all seem to expect files (and sub-directories recursively) to be copied from src/main/resources to classes on each build, and I could copy them explicitly the way I do with the Ant build now. But if SBT had a web-app-defaults, maven-defaults, or java-defaults template or something, that would be helpful to know about.

Upvotes: 1

Views: 2429

Answers (1)

Alexey Romanov
Alexey Romanov

Reputation: 170899

I think it should be

target := base / "WEB-INF"

or

classDirectory := base / "WEB-INF" / "classes"

Upvotes: 3

Related Questions