Instalación de groovy

Comenzando: Java

Groovy requires Java, so you need to have a version available (1.4 or greater is required). Here are the steps if you don't already have Java installed:

Puesta a punto del entorno

Download the Groovy installer or binaries from the downloads page and follow the installation instructions. (There is currently an issue where you cannot have spaces in the path where Groovy is installed under windows. So, instead of accepting the default installation path of c:\Program Files\Groovy you will want to change the path to something like c:\Groovy)

OR

Instalación de archivos jar opcionales

You may wish to obtain optional jar files, either corresponding to Groovy modules (see module documentation for details) or corresponding to other Java classes you wish to make use of from Groovy. Some possibilities are listed below:

Name                    From                            Description
jtds-version.jar        http://jtds.sourceforge.net     Database driver for SQL Server and/or Sybase
hsqldb-version.jar      http://www.hsqldb.org/          Database driver for HSQLDB, a 100% Java database

The recommended way for making Groovy be aware of your additional jar files is to place them in a predefined location. Your Groovy install should include a file called groovy-starter.conf.

Here is mine:
root@nereida:/usr/local/src/groovy/groovy-1.6.5/target/install/conf# ls -l
total 4
-rw-r--r-- 1 root root 893 2009-11-11 16:39 groovy-starter.conf
root@nereida:/usr/local/src/groovy/groovy-1.6.5/target/install/conf# cat -n groovy-starter.conf
     1  ##############################################################################
     2  ##                                                                          ##
     3  ##  Groovy Classloading Configuration                                       ##
     4  ##                                                                          ##
     5  ##############################################################################
     6
     7  ##
     8  ## $Revision: 9225 $ $Date: 2007-11-15 21:17:45 +0100 (Do, 15. Nov 2007) $
     9  ##
    10  ## Note: do not add classes from java.lang here. No rt.jar and on some
    11  ##       platforms no tools.jar
    12  ##
    13  ## See http://groovy.codehaus.org/api/org/codehaus/groovy/tools/LoaderConfiguration.html
    14  ## for the file format
    15
    16      # load required libraries
    17      load !{groovy.home}/lib/*.jar
    18
    19      # load user specific libraries
    20      load !{user.home}/.groovy/lib/*.jar
    21
    22      # tools.jar for ant tasks
    23      load ${tools.jar}

Within that file, make sure a line such as

load ${user.home}/.groovy/lib/*

is not commented out. The user.home system property is set by your operating system. Now simply place your jar files into the .groovy/lib directory.

As an alternative, you can set up a CLASSPATH variable and make sure it mentions all of your additional jar files, otherwise Groovy works fine with an empty or no CLASSPATH variable.

Programa de prueba

generaciondecodigos@nereida:~/src/groovy/separatedcomp$ cat hello.groovy
println "Hello World!"

Makefile

generaciondecodigos@nereida:~/src/groovy/separatedcomp$ cat Makefile
run: hello.class
        java -classpath /usr/local/src/groovy/groovy-1.6.5/target/install/embeddable/groovy-all-1.6.5.jar:. hello
hello.class: hello.groovy
        groovyc hello.groovy
clean:
        rm -f hello.class

Variables de entorno

export JAVA_HOME=/usr/lib/jvm/java-6-openjdk/
PATH=$PATH:/usr/local/src/groovy/groovy-1.6.5/target/install/bin/
GROOVY_HOME=/usr/local/src/groovy/groovy-1.6.5/target/install/

Ejecución

generaciondecodigos@nereida:~/src/groovy/separatedcomp$ make clean
rm -f hello.class
generaciondecodigos@nereida:~/src/groovy/separatedcomp$ make
groovyc hello.groovy
java -classpath /usr/local/src/groovy/groovy-1.6.5/target/install/embeddable/groovy-all-1.6.5.jar:. hello
Hello World!



Subsecciones
Casiano Rodríguez León
2010-04-30