1

I have a script that I quickly put up using a @Grab annotation to import a package - namely HttpBuilder. Now I would like to actually install HttpBuilder and get rid of the annotation before putting the script in production - I do not want to grab the dependency dynamically on the prod server.

How do I actually tell Grape to install the dependency once and for all? Is there even a way to do this? If not, how should I install this package before deploying?

EDIT Following the advice from tim_yates, I donwloaded all teh JARs from HttpBuilder website, and added them to the classpath. But, when I run groovy -cp dependencies/* myApp.groovy what I get is a bunch of errors like

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
/path/to/dependencies/httpclient-4.0.3.jar: 1: unexpected char: 0x3 @ line 1, column 3.
   PK
     ^

What does this mean?

M. Justin
  • 14,487
  • 7
  • 91
  • 130
Andrea
  • 20,253
  • 23
  • 114
  • 183

1 Answers1

1

If you go to the Downloads page for HttpBuilder, you can follow the links in the first paragraph and download the http-builder-xxx-all.zip for the release you want...

Expand this, and it contains the jar, and the dependency jars in the dependencies folder

Then, just add them to the classpath in the usual way and get rid of the @Grab line

tim_yates
  • 167,322
  • 27
  • 342
  • 338
  • @Andrea looks like there's something wrong with the download...one sec, I'll check... – tim_yates Jul 06 '12 at 12:20
  • @Andrea I just tried with the 0.5.3 [snapshot from here](http://snapshots.repository.codehaus.org/org/codehaus/groovy/modules/http-builder/http-builder/0.5.3-SNAPSHOT/http-builder-0.5.3-20111229.173616-1-all.zip), unzipped it, and ran `groovy -cp http-builder-0.5.3-SNAPSHOT.jar:dependencies/* test.groovy` (where test.groovy is [this script here](http://groovy.codehaus.org/modules/http-builder/doc/index.html)), and it all worked fine... – tim_yates Jul 06 '12 at 12:25
  • Ok, let me try again with another download – Andrea Jul 06 '12 at 12:26
  • Ok, it turns out that the problem was that I actually moved http-builder inside dependencies and ran `groovy -cp dependencies/* test.groovy`. What is wrong with it? Excuse me, I am a newbie on the JVM – Andrea Jul 06 '12 at 12:33
  • @Andrea Ahhhh... When you just have a path with a wildcard, the shell jumps in and replaces the wildcard with the expanded list of files (separated by space), so you end up with the command: `groovy -cp dependencies/a.jar dependencies/b.jar ...etc... test.groovy` So groovy tries to load the `b.jar` as your script, and falls on its face. Try: `groovy -cp "dependencies/*" test.groovy` By quoting the -cp parameter, it should make it into the JVM as it is, without bash trying to be helpful and messing it up... – tim_yates Jul 06 '12 at 12:37