Over a million developers have joined DZone.

Using groovy scripts in your application deployment

· Java Zone

Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway?  Brought to you in partnership with IBM.

We distribute our application as tar.gz on Linux.
Our server is actually jetty with our web application, but we want to make some checks before the server start in order to provide clear error messages w/o need for a user to scan log files.  So I wrote the server start script in groovy and packed groovy installation (and JRE as well) into the application distribution.
The problem was, however, that groovy script can't run by itself (like shell script), so I wrapped the script into the shell script.

Assuming that our installation looks like
tools/jre
tools/groovy
server/bin/myscript
server/groovy/myscript.groovy
server/groovy/SomeClass.groovy
lib/myjar.jar
the shell script "myscript" will looks like:
#!/bin/sh

server_bindir=`/usr/bin/dirname $0`; 
server_bindir=`(cd $server_bindir;pwd)`; #get absolute path
server_dir=`dirname $server_bindir`;
server_groovy_dir=$server_dir/groovy

install_home=$server_dir/..;
jars_dir=$install_home/lib


JAVA_HOME=$install_home/tools/jre
export JAVA_HOME


$install_home/groovy/bin/groovy -cp $server_lib_dir:$jars_dir/myjar.jar $server_lib_dir/myscript.groovy  $* 

Discover how the Watson team is further developing SDKs in Java, Node.js, Python, iOS, and Android to access these services and make programming easy. Brought to you in partnership with IBM.

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}