Tài liệu Groovy Recipes doc

254 4.9K 1
Tài liệu Groovy Recipes doc

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

[...]... environment variables Make sure that GROOVY_ HOME appears To verify that the Groovy command is in the path, type groovy -version If you see a message similar to this, then you have successfully installed Groovy: Groovy Version: 1.5.0 JVM: 1.5.0_13-119 2.2 Running a Groovy Script (groovy) // hello .groovy println "Hello Groovy World" $ groovy hello .groovy $ groovy hello ===> Hello Groovy World One of the first... officially a Groovy developer Welcome to the club For more on running uncompiled Groovy, see Chapter 5, Groovy from the Command Line, on page 86 2.3 Compiling Groovy (groovyc) $ groovyc hello .groovy // on Unix, Linux, and Mac OS X $ java -cp $GROOVY_ HOME/embeddable /groovy- all-1.5.0.jar: hello ===> Hello Groovy World // on Windows $ java -cp %GROOVY_ HOME%/embeddable /groovy- all-1.5.0.jar; hello ===> Hello Groovy. .. Chapter 4, Java and Groovy Integration, on page 69 2.4 Running the Groovy Shell (groovysh) $ groovysh Groovy Shell (1.5.0, JVM: 1.5.0_13-119) Type 'help' or '\h' for help -groovy: 000> println "Hello Groovy World" Hello Groovy World ===> null The Groovy shell allows you to work with Groovy interactively There is no need to create a file or compile anything—simply type groovysh at the command... following: ### Groovy GROOVY_HOME=/opt /groovy PATH=$PATH: $GROOVY_ HOME/bin export GROOVY_ HOME PATH For these changes to take effect, you need to restart your terminal session Alternately, you can type source bash_profile to load the changes into the current session You can type echo $GROOVY_ HOME to confirm that your changes took effect: $ echo $GROOVY_ HOME /opt /groovy To verify that the Groovy command... want to create Groovy scripts if you want to do anything more than quick-and-dirty playing around To create a Groovy script, create a new text file named hello .groovy Add the following line: println "Hello Groovy World" 27 C OMPILING G ROOVY ( GROOVYC ) Save the file, and then type groovy hello .groovy at the command prompt Since you gave it a groovy file extension, you can also type just groovy hello Congratulations!... syntax error The :000 at the prompt indicates how many lines of Groovy code have been typed without being run For example, you can define a class on the fly in the Groovy shell and use it right away (Of course, the class goes away once you exit the shell.) groovy: 000> groovy: 001> groovy: 002> groovy: 003> groovy: 004> groovy: 005> ===> true groovy: 000> ===> Hi! My class Person{ String name String toString(){... following page 2.6 Running Groovy on a Web Server (Groovlets) 1 2 3 4 Copy $GROOVY_ HOME/embeddable /groovy. jar to WEB-INF/lib Add groovy. servlet.GroovyServlet to WEB-INF/web.xml Place your Groovy scripts wherever you'd normally place your JSP files Create hyperlinks to your Groovy scripts Adding a single Groovy servlet to your web application gives you the ability to run uncompiled Groovy scripts on the... (G ROOVLETS ) Figure 2.2: The Groovy object browser The Groovy servlet acts like the groovy command on the command line—it compiles your groovy scripts on the fly To get started, copy groovy. jar from $GROOVY_ HOME/embedded into the WEB-INF/lib directory of your JEE application This Groovy- enables your entire web application To run Groovlets on the fly, add the groovy. servlet GroovyServlet entry to the WEB-INF/web.xml... how to install Groovy, how to compile Groovy code, and how to Groovy- enable a text editor or IDE Chapter 3, New to Groovy, on page 41 is a “red pill” chapter, showing experienced Java developers all the interesting new features Groovy brings to the party: duck typing, Groovy truth, and closures Chapter 4, Java and Groovy Integration, on page 69 is a “blue pill” chapter, demonstrating how Groovy can be... path, type groovy -version If you see a message similar to this, then you have successfully installed Groovy: Groovy Version: 1.5.0 JVM: 1.5.0_13-119 Installing Groovy on Windows Download the latest Groovy ZIP file from http:/ /groovy. codehaus.org Unzip it to the directory of your choice I prefer c:\opt You will end up with a groovy directory that has the version number on the end of it, such as groovy- 1.5 . Installing Groovy . . . . . . . . . . . . . . . . . . . . . . 24 2.2 Running a Groovy Script (groovy) . . . . . . . . . . . . 27 2.3 Compiling Groovy (groovyc). 28 2.4 Running the Groovy Shell (groovysh) . . . . . . . . . . 28 2.5 Running the Groovy Console (groovyConsole) . . . . . 33 2.6 Running Groovy on a Web

Ngày đăng: 18/02/2014, 06:20

Mục lục

    Groovy, the Way Java Should Be

    Stripping Away the Verbosity

    Groovy: The Blue Pill or the Red Pill?

    Running a Groovy Script (groovy)

    Running the Groovy Shell (groovysh)

    Running the Groovy Console (groovyConsole)

    Running Groovy on a Web Server (Groovlets)

    Groovy + [Insert Your IDE or Text Editor Here]

    Optional Datatype Declaration (Duck Typing)

    Java and Groovy Integration

Tài liệu cùng người dùng

Tài liệu liên quan