I am working on a sample scalatra webapp. I have created one more service jar which contains dao and service layer. I want to add this dependency in Scalatra-SBT project. How can i achieve this?
I bundled my service jar using command : SBT package which created a jar. How will i include this jar in web application? Can i add this in build.scala file? or can i copy into any Webapp folder ?
Is it possible to push this jar to local repository and pull it from there when my webapp builds?
Whew! Lots of questions here!
The good news is that SBT can do all of the tasks that you are asking for.
DO NOT copy JAR files around to satisfy dependencies! It will end up in tears, virtually guaranteed. Tools like Ivy and Maven (and by extension, SBT) are here to help.
To push your service jar to a local repo:
The SBT task is
publish-local
, i.e.sbt publish-local
from your service jar's root directory. You'll see lots of descriptive output, finishing up with lines in the following format:[info] published services_2.10 to /Users/millhouse/.ivy2/local/services/services_2.10/0.1-SNAPSHOT/jars/services_2.10.jar
You don't need to do anything special in your
build.sbt
to make this work, as long as you have thename
andscalaVersion
variables set. Note that this will publish to your local Ivy cache, which is$HOME/.ivy2/local
for most people.To get your Scalatra-SBT webapp to pick up your service jar:
Edit your webapp's
project/build.scala
, adding this dependency under thelibraryDependencies
key (there should already be a few dependencies, one per line, put yours somewhere in the middle!):"services" %% "services" % "0.1-SNAPSHOT",
Perform an
sbt clean update
and your dependency will be pulled in. If it doesn't work, SBT will give you a list of the places where it looked for the artifacts; compare it closely with the location that they were published to (in the previous step) and you'll probably find a typo; fix it and try again.Please note that there is a lot more to dependency and release management than I've shown above, but this should be enough to get you going.