Thursday, June 25, 2015

How to create executable JAR from single Groovy script

Groovy scripts are nice - they allow to use dependencies and write logic in small single file, but Groovy is mostly available on developers machine, but not on servers, so deploying them is a little more tricky. You can package them in uberjar with Gradle, but it requires additional build file and compatible structure, so it is more like project than script already.

To keep things simple, I have created Groovy script that converts other Groovy scripts into executable JARs. It packages all dependencies from Grab and compiles original script into Java main class with same name as script and sets it in manifest. So it is perfectly usable from empty JVM. JAR structure is also compatible with AWS lambda, so it can be launched from there too, just put logic in specific method. To convert your script, just download it from here and run like:

./scriptjar.groovy input.groovy output.jar

Script tries to find groovy libs via GROOVY_HOME, so set it or just hack it for your location, it is just one small Groovy script.

10 comments:

  1. Thank you for your article. I also search that information, and when I was read yours, it became useful to me. I may recommend to you good advice how to open jar file https://wikiext.com/jar here. There is an instruction and exactly the right file, which you need to download, in case you will have bugs.

    ReplyDelete
  2. After reading this web site I am very satisfied simply because this site is providing comprehensive knowledge for you to audience.
    Thank you to the perform as well as discuss anything incredibly important in my opinion. We loose time waiting for your next article writing in addition to I beg one to get back to pay a visit to our website in



    Selenium training in bangalore
    Selenium training in Chennai
    Selenium training in Bangalore
    Selenium training in Pune
    Selenium Online training

    ReplyDelete
  3. ./scriptjar.groovy input.groovy output.jar -> where to execute this command ? In Command prompt ? I tried in CMD and got '.' is not recognized as an internal batch command

    ReplyDelete


  4. org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
    script15681542317091305207412.groovy: 9: expecting '(', found 'n' @ line 9, column 12.
    while n <= 25:
    ^

    1 error


    Groovy Version: 2.5.8 JVM: 11.0.3 Vendor: SAP SE OS: Linux
    Open JDK 11

    ReplyDelete
  5. it's a very nice script. good detail in groovy. they are best useful in this script cmd. og whatsapp

    ReplyDelete
  6. TubeDigger 7.5.1 Crack Full Version is a fast video downloading software. It can also directly convert them into various video versions. TubeDigger License Key

    ReplyDelete
  7. Microsoft Office 2016 Product Key for Free 100% Working Microsoft Office 2016 is the latest version. ... Office 2016 Pro Plus Product Key Generator:. Office 2016 Crack Download

    ReplyDelete
  8. Good Morning Wishes For Husband Get up your spouse up romantically from the early morning he could start his day together. Good Morning MSG For Husband

    ReplyDelete