ICE09 . playing with java, scala, groovy and spring .

Playing with Spring

Archive for December, 2010

QuickTip: SCP with Groovy, Maven and Eclipse

Posted by ice09 on December 20, 2010


It’s easy to use SCP with Java, Groovy and even with Maven. However, it gets more complicated if you want to use all of them simultaneously.

It should work this way: An (key-file-based) SCP-connection should take place in a Groovy, so the transferred file can be manipulated straight away. All this should be triggered by a Maven build process and alternatively, using Eclipse with the Groovy plugin, it should be possible to directly start the Groovy script.


Either Eclipse with the Groovy plugin and the Maven plugin or the SpringSource Tool Suite (which includes both plugins) should be installed.

Maven config

The Maven config consists of two dependencies:

  1. The Ant-SCP-Plugin, which is based on JSch
  2. Embedded Groovy (groovy-all.jar)

And two Maven Plugins:

  1. GMaven
  2. The Exec Maven Plugin

<project xmlns="" xmlns:xsi=""


Here comes the Groovy part, in fact it’s quite short, since it focuses on the file transfer part. Obviously, it would be easy to manipulate the transferred files after the SCP-transfer, since we are inside a Groovy script and we can use whatever Java library we want since we are inside a Maven project. The universe is ours!

package de.ice09.scp

new AntBuilder()

The file must go to src/main/groovy for GMaven to work. The key must be OpenSSH-compliant. If you use PuTTY, you can export this format. Alternatively, you can use username/password instead.


After creating a new Maven project with the pom.xml listed above, more than half of the work is done. With or without an IDE this can be tested. Just run

maven clean install exec:java

GMaven should generate the Java stubs, the Execution Plugin should execute the generated Java class file. The dependencies for JSch, Antbuilder etc. are handled by Maven or Groovy itself.

Eclipse config

The final step is to enable the Groovy nature in Eclipse. This leads us to a faster development cycle, since the Groovy script can be run “natively”, without having Maven to generate the Java stub before. There is no problem running the two options (Groovy with Maven and Eclipse) side-by-side, so it is really easy to develop and deploy, since there is no big difference. You always have a completely runnable version available, given that Maven is installed on the target system.

Convert to Groovy project


Add Groovy sources (from src/main/groovy) to classpath


The deployable way: start process using GMaven and Execution Plugin

2010-12-20_23-36_Run Configurations

Start in development mode using the Groovy Eclipse Plugin


Posted in Groovy, Maven | 1 Comment »

Preparing a fresh Debian Lenny for Java Enterprise Applications

Posted by ice09 on December 18, 2010


I am a happy owner of a virtual root server – this being a great thing, there is one big problem: I have to prepare this box for Java usage myself. This must be achieved with a somewhat limited Linux knowledge. However, with debian lenny this turned out to be a breeze.

I had to follow the steps below to get this running in about 30 minutes:

  1. Apache Webserver
  2. MySQL
  3. phpMyAdmin
  4. GlassFish 3

Which is pretty much what you need for creating JEE/Spring-Applications in an enterprise scale.

What is still missing (due to a lack of time and necessity) are the following configurations:

  1. JNDI-Resource for the MySQL-Database
  2. Apache/GlassFish-mod for forwarding requests on port 80 to GlassFish directly

List of Commands

cat /etc/debian_version

For my installation this says 5.0.7. So obviously: 1. I am using Debian. 2. It is Debian Lenny in version 5.0.7. Yes, we are starting slowly here.

apt-get install apache2

Install the Apache Web Server. I more or less need it for phpMyAdmin. Obviously, you can choose lighthttpd or others here.

apt-get install mysql-server mysql-client phpmyadmin

This is the most important line, it magically does everything exactly like you want to have it (however, this depends on answering the questions during installation correctly).

apt-get install sun-java6-jdk

Ok, this is important as well for Java development. I did not expect it to be that easy (remembering licensing issues in the past) and tried it “manually”, but was lost almost immediately. However, with sun-java6-jdk, you will get everything you need. You should check this with:

java –version

which should print out text like this:

java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03, mixed mode)

Your mileage may vary here of course. It should show 1.6 somewhere though.

Now, the most “difficult” part is the installation of GlassFish. Not surprisingly, we are not the first trying to install GlassFish on Debian, so there exists a really good documentation about this topic here (in German):

Since this HOWTO here should be complete, I am reposting the steps here:

wget -O /opt/
cd /opt/
cd /etc/init.d/

Now, only the script is missing:

vim /etc/init.d/
chmod 0755    
update-rc.d defaults

with this content (all taken from the site mentioned above):

# Provides:          glassfish
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start daemon at boot time
# Description:       Enable service provided by daemon.
# This init.d script is used to start the glassfish application server.
# Simplest possible case -- no password file, one default domain
case "$1" in
	$GLASSFISH_HOME/bin/asadmin start-domain | tee -a /var/log/glassfish.log
	$GLASSFISH_HOME/bin/asadmin stop-domain | tee -a /var/log/glassfish.log
	$GLASSFISH_HOME/bin/asadmin restart-domain | tee -a /var/log/glassfish.log
    echo "usage: $0 (start|stop|restart|help)"

Posted in Debian, GlassFish | 2 Comments »