Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure build.sbt so that xsbt-web-plugin a creates war file without compression?

I am using Scala 2.10.1 with sbt to package my webapp as a war file. For the purpose of efficient rsync deltas, I'd like to have the war packaged as a .war file, but without zip compression. I just need to know how to configure my build for this.

UPDATE:
All these plugin docs assume all this knowledge of how the syntax works and how to combine tasks into a new task, etc. I can't even tell how to create a new task that does package then command. None of the answers so far have said specifically, "here's what you do.."

Just to be clear, this is all I'm asking for:

I need a Task "packnozip" that does this:

1) run "package"

2) run shell commands:

$ mkdir ./Whatever 
$ pushd ./Whatever 
$ jar xvf ../Whatever.war 
$ popd 
$ mv ./Whatever.war ./Whatever.war.orig 
$ jar cvM0f ./Whatever.war -C ./Whatever . 

So what i'm saying is i want to type "packnozip" into the sbt console and have it do #1 then #2.

For now i'm just manually doing #2 which seems silly if it can be automated. Also watching a 30MB file get completely resent by rsync b/c it is not diffable seems quite silly when a 34MB uncompressed file is only 13% more data, and takes a fraction of second to send b/c of efficient diffs, not to mention "-z" will compress the transfer anyways.

like image 254
jpswain Avatar asked Nov 03 '22 19:11

jpswain


1 Answers

If you have your war file unzipped in a directory you can:

zip -r -0 project.war project/

That should be zero compression. In case you don't see those options, this is my setup:

[node@hip1 dev]$ zip -v
Copyright (c) 1990-2008 Info-ZIP - Type 'zip "-L"' for software license.
This is Zip 3.0 (July 5th 2008), by Info-ZIP.

Which, you could execute as a run task I believe, after the war is packaged.

UPDATE 1

I believe this is the best way to achieve your needs:

http://www.scala-sbt.org/release/docs/Detailed-Topics/Process

val exitcode = "zip -r -0 project.war project/"!

However, if you need to work from a specific directory (Please see Update 2 below):

Modified this to execute within directory but place .war above directory. The path (2nd) argument should include the directory, so that the zip is performed inside of it:

Process("zip" :: "-r" :: "-0" :: "../project.war" :: "." :: Nil, "/path/to/project/") !

Here's another SO question on the ProcessBuilder that may help as well:

How does the “scala.sys.process” from Scala 2.9 work?

(Note: you don't need to import scala.sys.process._)

UPDATE 2

For readers in the future, please note that zipping the project directory itself will not work, one needs to perform the zip of the war inside the directory by using pushd, putting the resulting war outside of the directory as mentioned by the OP in the comments below this answer. As Orange80 mentioned:

pushd ./project && zip -r -0 ../project.war ./ && popd

UPDATE 3

Check out this, it may do exactly what you need, with a 0 for options to specify no compression:

https://github.com/sbt/sbt-onejar

a plugin that lets you create a single executable jar, which, with options (for example "0" as in a command like "jar 0f blah.jar blah/") can be made I think as you mentioned in the comments below to create the jar file without compression.

For usage I found this on SO: SBT one-jar plugin

And also, if it needs to be modified, it's a pretty reasonable example of a plugin as well, which if you drop it in your home ~/.sbt/plugins it will be global and can be used in your build in the fashion noted in the SO answer above. I hope that helps at least a little bit/

like image 106
Matt Mullens Avatar answered Nov 15 '22 07:11

Matt Mullens