From XennisWiki
Jump to: navigation, search

Apache Groovy is an object-oriented programming language for the Java platform. It is a dynamic language with features similar to those of Python, Ruby, Perl, and Smalltalk. It can be used as a scripting language for the Java Platform, is dynamically compiled to Java virtual machine (JVM) bytecode, and interoperates with other Java code and libraries. Groovy uses a Java-like curly-bracket syntax. Most Java code is also syntactically valid Groovy, although semantics may be different. (Wikipedia)

Download und Installation

Voraussetzung ist die Java Virtual Machine.

Installation (Windows)

Ausführliche Hilfe: Installing Groovy

  • Füge die Systemvariable GROOVY_HOME hinzu (Der Pfad muss entsprechend angepasst werden): C:\Program Files\Groovy\groovy-2.0.2
  • Zum Testen gibt in Konsole ein: groovy --version

IDE Integration


Offizielle Seite: Eclipse Plugin

Ausführliche Hilfe: Install Groovy-Eclipse Plugin, Eclipse Erweiterung installieren


In NetBeans ist für Groovy kein Plugin notwendig, sondern es muss nur die entsprechende Version der IDE heruntergeladen werden. Siehe Artikel NetBeans


Read and write file

See also: Groovy Documentation - Reading Files Line by Line

// input file
String inputFileName = ""
def inputFile = new File(inputFileName)
if (!inputFile.exists()) {
	println "input file does not exits"

// output file
String outputFileName = inputFileName - '.in' + '.out'
def outputFile = new File(outputFileName)
if (outputFile.exists()) {

// Read input file
def lines = inputFile.readLines()
int N = lines.get(0).toInteger()
int[] P = lines.get(1).split(" ").collect {it as int} as int[]

// Write output file						
outputFile << "Case ${N + 1}\n"

See also

External links