Java
Setting Up Development Environment For Grails on GNU/Linux
3In couple of my previous posts, I have explained how to install Grails and required packages to get a Grails development environment on the Windows platform. Continuing the Grails series, the current post explains how to set up a development environment for Grails web application framework on a GNU/Linux distribution. An alternative easier but less flexible method is noted to at the bottom of the post.
To setup Grails development environment on your GNU/Linux box, you first need to install Java SDK and Groovy packages.
-
Install Sun Java SDK 6 according to the instructions for your GNU/Linux distribution.
- For example, in Ubuntu you can install it like this:
- Make sure that the multiverse respository is enabled. Go to System -> Adminstration -> Synaptic Package Manager.
- In Synaptic Package Manager, go to Settings -> Repositories.
- Enable the multiverse repository if not already enabled.
- Click the Close button. Click Reload button on the toolbar to reload the package list.
- In Synaptic Package Manager, search for the “jdk” package(use Edit -> Search or Search button on the toolbar).

Scroll down the result list until you find Sun JDK 6 package, then right-click on it and select “Mark for installation.”

Click the Apply button on the toolbar to install the Sun JDK package.
You can also install it from the command line in one simple step:
# sudo aptitude install sun-java6-jdkYou can similarly use ‘emerge’ command in Gentoo, ‘yum’ command in Fedora GNU/Linux distributions. You can also simply download the compressed Sun JDK 6 binary archive for GNU/Linux, uncompress it in the home directory and set its bin directory in the PATH environment variables. For more information, read Sun’s JDK 6 installation notes for GNU/Linux(Yes, it’s ugly).
- To confirm that Java is installed and available in the system path, run the following commands:
tabrez@tabrez-ubuntu-vm:~$ java -version ; javac -version
java version “1.6.0_06″
javac 1.6.0_06 - Create a new system environment variable in your profile file (e.g. $HOME/.profile or /etc/.profile or /etc/environment – whatever you prefer the most) called JAVA_HOME and set it to your Java SDK installation directory path.
export JAVA_HOME=/usr/lib/jvm/java-6-sun/
Run the source command to apply the profile changes to the environment immediately without needing a session or OS restart.
# source $HOME/.profile
# echo $JAVA_HOME
/usr/lib/jvm/java-6-sun/
- For example, in Ubuntu you can install it like this:
-
Download and configure Groovy package.

Download the compressed archive package of Groovy from its download page to your home directory and uncompress it.#cd $HOME
# wget http://dist.groovy.codehaus.org/distributions/groovy-binary-1.5.6.zip
# unzip groovy-binary-1.0.2.zip
# mv groovy-binary-1.0.2 grails(Remember to download the latest stable version available on the Groovy download page.)
Create GROOVY_HOME environment variable in your profile file(just like you created the JAVA_HOME variable) and set it to the directory where you have uncompressed the Groovy package. Add Groovy’s bin directory to the PATH environment variable
export GROOVY_HOME=/home/tabrez/groovy/
export PATH=$PATH:$GROOVY_HOME/binCheck the version of Groovy.
# groovy -v
Groovy Version: 1.5.6 JVM: 10.0-b22 -
Download and configure Grails package.

Download the compressed archive package of Grails from its download page to your home directory and uncompress it.#cd ~
# wget http://dist.codehaus.org/grails/grails-bin-1.0.3.zip
# unzip grails-bin-1.0.3.zip
# mv grails-bin-1.0.3 grails(Remember to download the latest stable version available on the Grails download page. You can also download the compressed tar version(.tar.gz) if you don’t have the unzip command installed on your distribution.)
Create GRAILS_HOME environment variable and set it to the directory where you have uncompressed the Grails package(just like you created the JAVA_HOME variable). Add Grails’s bin directory to the PATH environment variable.
export GRAILS_HOME=/home/tabrez/grails/
export PATH=$PATH:$GROOVY_HOME/bin:$GRAILS_HOME/binMake the grails command executable and check the version of Grails.
# cd $HOME
# chmod +x grails/bin/grails
# grails -v
Welcome to Grails 1.0.2 – http://grails.org/ -
Testing the Grails Development Environment on GNU/Linux.
Now go to the post that explains how to create a Grails “Hello, World” web application to test if your Grails development environment is properly setup. It is for the Windows platform but I think that you should be able to adapt it to other platforms too. If you get into any problems, check if all the environment variables are properly set.

You can also post the error messages that you are getting somewhere on the Internet and provide the link to it in the comment section below. -
Next: Alternative easy way to set up Grails development environment using package managers
There is also an easy way to setup Grails development environment using the package managers of different GNU/Linux distributions. Like installing Groovy and Grails packages in Ubuntu using the apt-get command. This easy model has certain limitations though like support only for old versions of Java, Groovy and/or Grails.
I will discuss more about it in the next post.Done.
What Experts Say About The Java Language: Humorous Quotes
18There has been so much hype and misinformation spread about the Java language and related technologies that it feels imperative to correct some of those myths associated with it. Far from attempting to put to rest many false acclamations about the language, here is just a small collection of my favourite quotes about the Java language and its ‘killer features’, some of them by the people who have a special interest in programming language design.
“Ten years from now, Java will be taught in every university. Not in the engineering or computer science departments, but in the business and marketing courses. Java is one of the best examples of the triumph of marketing over technology.” –Jim Turley
Isn’t it both true and funny? Or is it funny only because it is true? Just as one example, remind yourself about the hype created over the plarform indenpendence of the Java language. Write once, Run everywhere. How true this statement has turned out to be is no big secret today. The following extract from the book ‘Inside Java Virtual Machines’ is NOT a humorous quote. Well, read it on your
own and find out if it sounds funny or not regarding the BIG promise of Java about the platform independence.
Seven Steps to Platform Independence
- Choose a set of host computers and devices that you will claim your program runs on (your “target hosts”).
- Choose an edition and version of the Java Platform that you feel is well enough distributed among your target hosts. Write your program to run on this version of the Java Platform.
- For each target host, choose a set of Java Platform implementations that you will claim your program runs on (your “target runtimes”).
- Write your program so that it accesses the host computer only through the standard runtime libraries of the Java API. (Don’t invoke native methods, or use vendor-specific libraries that invoke native methods.)
- Write your program so that it doesn’t depend for correctness on timely finalization by the garbage collector or on thread prioritization.
- Strive to design a user interface that works well on all of your target hosts.
- Test your program on all of your target runtimes and all of your target hosts.
If you follow the seven steps outlined above, your Java program will definitely run on all your target hosts.
–Bill Venners[Chapter 2 of Inside the Java Virtual Machine]
After criticising all the features of C++ that were not included in Java to be ‘unncessary sources of complexities in the programs’, generics(and enums etc) were added to the language eventually(perhaps too late in the day). After referring to C++ as a legacy/obsolete language right since the first release of the Java language, C++ language support is now being included in even a popular Java IDE like NetBeans.
Sun announces C/C++ support for NetBeans IDE
March 23, 2006Why support an old, legacy, complex and idiotic language in 2006??
–Unknown Source
Alexander Stepanov is the creator of STL. He claims that he has not found his ideal language in any of the existent ones and would love to create one if he is funded by someone. Let’s hear what he has to say about Java language:
“I spent several months programming in Java. Contrary to its author’s prediction, it did not grow on me. I did not find any new insights – for the first time in my life programming in a new language did not bring me new insights. It keeps all the stuff that I never use in C++ – inheritance, virtuals – OO gook – and removes the stuff that I find useful. It might be successful… but it has no intellectual value whatsoever”
–Alexander Stepanov
It was refreshing to hear similar sentiments expressed about the Java language by someone else too. Though Java has been useful in solving many a problems more easily than some of the other languages, ‘no intellectual value whatsoever’ quality of it has exactly been my own opinion about the language. It fails to teach anything new to someone who already knows a few other languages.
Alex Stepanov continues:
“It[Java] might be successful – after all, MS DOS was – and it might be a profitable thing for all your readers to learn Java, but it has no intellectual value whatsoever. Look at their implementation of hash tables. Look at the sorting routines that come with their “cool” sorting applet. Try to use AWT. The best way to judge a language is to look at the code written by its proponents. “Radix enim omnium malorum est cupiditas” – and Java is clearly an example of a money oriented programming (MOP). As the chief proponent of Java at SGI told me: “Alex, you have to go where the money is.” But I do not particularly want to go where the money is – it usually does not smell nice there.”
Answering another question about the difference between Generic programming and OO programming, Alex replies:
“My approach[Generic Programming] works, theirs[OO Programming] does not work. Try to implement a simple thing in the object oriented way, say, max. I do not know how it can be done. Using generic programming I can write:
[Example Generic Code for max routine]
Try doing it in Java. You can’t write a generic max() in Java that takes two arguments of some type and has a return value of that same type. Inheritance and interfaces don’t help. And if they cannot implement max or swap or linear search, what chances do they have to implement really complex stuff? These are my litmus tests: if a language allows me to implement max and swap and linear search generically – then it has some potential.“
Here is what Alex feels about Object Oriented paradigm:
“And I had many false starts. For example, I spent years trying to find some use for inheritance and virtuals, before I understood why that mechanism was fundamentally flawed and should not be used.”
More on Object Oriented paradigm by Alex:
“I think that object orientedness is almost as much of a hoax as Artificial Intelligence. I have yet to see an interesting piece of code that comes from these OO people. In a sense, I am unfair to AI: I learned a lot of stuff from the MIT AI Lab crowd, they have done some really fundamental work: Bill Gosper’s Hakmem is one of the best things for a programmer to read. AI might not have had a serious foundation, but it produced Gosper and Stallman (Emacs), Moses (Macsyma) and Sussman (Scheme, together with Guy Steele). I find OOP technically unsound. It attempts to decompose the world in terms of interfaces that vary on a single type. To deal with the real problems you need multisorted algebras – families of interfaces that span multiple types. I find OOP philosophically unsound. It claims that everything is an object. Even if it is true it is not very interesting – saying that everything is an object is saying nothing at all. I find OOP methodologically wrong. It starts with classes. It is as if mathematicians would start with axioms. You do not start with axioms – you start with proofs. Only when you have found a bunch of related proofs, can you come up with axioms. You end with axioms. The same thing is true in programming: you have to start with interesting algorithms. Only when you understand them well, can you come up with an interface that will let them work. ”
Java is termed to be a superior language for the simple reason that it is (claimed to be) a purely object oriented language. Even if we buy this contrived claim by Sun and those who trust their word,
The entire interview is very educative and insightful: Alex Stepanov’s Interview
Bjarne Stroustrup has always been guarded when making statements about the programming languages other than his own. He plainly refused to compare any language with C++ for obvious reasons. A few words that he did speak about Java/C# were very interesting and devoid of any bias.
Much of the relative simplicity of Java is – like for most new languages – partly an illusion and partly a function of its incompleteness. As time passes, Java will grow significantly in size and complexity. It will double or triple in size and grow implementation-dependent extensions or libraries. That is the way every commercially successful language has developed. Just look at any language you consider successful on a large scale. I know of no exceptions, and there are good reasons for this phenomenon. [I wrote this before 2000; now see a preview of Java 1.5.]
Bjarne Stroustrup hitting the bull’s eye:
“Java isn’t platform independent; it is a platform. Like Windows, it is a proprietary commercial platform. That is, you can write programs for Windows/Intel or Java/JVM, and in each case you are writing code for a platform owned by a single corporation and tweaked for the commercial benefit of that corporation. It has been pointed out that you can write programs in any language for the JVM and associated operating systems facilities. However, the JVM, etc., are heavily biased in favor of Java. It is nowhere near being a general reasonably language-neutral VM/OS. “
This is from the FAQ on Bjarne Stroustrup’s home page:
Q: How can a legacy language like C++ compete with modern, advanced languages?
A: Naturally, calling C++ a legacy language shows a bias (see legacy code). That aside, people are usually thinking of Java or C# when they ask such a question. I will not compare C++ to those languages, but I can point out that “modern” doesn’t necessarily mean “better”, and that both Java and C# are rooted in 1980s style OOP to an even greater extent than early C++ was.
There are many more but these are some of my favourites about Java. What are your favourite quotes about the programming languages?
Java 1.5 and Eclipse in Gentoo – Part II
4My previous post discussed the installation of Java on a Gentoo system. Its all well as long as you want to run the default supported version of java on the Gentoo system – you install blackdown-jdk 1.4, Eclipse 3.0, and maybe Eclipse CDT too and get on with development. But if you want to install java 1.5(Tiger) then you need to unmask the package before you can install it and also remember to make blackdown(or sun) jdk 1.4 as the default JVM for the system. You can keep sun jdk 1.5 as the default JVM for the user. The procedure is like this:
[sun-jdk-1.5.0.06] “Sun JDK 1.5.0.06″ (/etc/env.d/java/20sun-jdk-1.5.0.06) *
[blackdown-jdk-1.4.2.03] “Blackdown JDK 1.4.2.03″ (/etc/env.d/java/20blackdown-jdk-1.4.2.03)
This shows you all the installed jdks on your system. Use the name as given under the brackets to set that particular jvm as your system default:
sh# /usr/sbin/env-update && source /etc/profile
This sets the blackdown jdk 1.4 as the system jvm, which is the recommended option. You can set the sun jdk 5.0 as the user default jvm though:
sh# echo source ~/.gentoo/java-env >> ~./bash_profile
sh# source ~/.gentoo/java-env
This sets the sun jdk 1.5 as the user jvm and it is safe this way. But don’t make 1.5 version as the default jvm for the system unless you are ready to break a lot of java applications.
Best way to install Java on Gentoo OS:
But this still is not an ideal setup from my point of view; the installed Eclipse version doesn’t support the Java 1.5 version. If you want to use the latest versions of all the java software without going through all of these hassles, you need to install everything related to java manaully in the user home directory. This won’t affect your normal portage structure in any way(but you still need a system jdk to run java applications from the browser).
First download the latest versions of Java SDK and the Eclipse IDE from the Internet and copy them into the home directory.
Download sun jdk 1.5.0 update 6 from here and copy it into the home directory. You will have to accept the license to be able to download this. Be sure to download the .bin version of the file and not the RPM version.
Download the latest version of the Eclipse IDE from here and copy it in the home directory. The latest build available currently is Eclipse 3.2M5a. If you plan to use Eclipse CDT plugin to create C++ applications, then you have to be content with the Eclipse 3.1.2 version.
(All the above links are for the gnu/linux, 32-bit operating system. Finding similar package files for 64-bit systems shouldn’t be too difficult)
Install jdk as a normal user:
sh# ./jdk_1_5_0_06-linux-i586.bin
sh# tar xvzf eclipse-sdk-3,1,2-linux-gtk.tar.gz
Rename the directory to which the above files are extracted to something simple, like “eclipse”.
Now add the following lines to your user profile( eg ~/.bash_profile ):
JDK_HOME=~/jdk1.5.0_06
JAVAC=~/jdk1.5.0_06/bin/javac
PATH=~/jdk1.5.0_06/bin:~/jdk1.5.0_06/jre/bin:~/eclipse:$PATH
MANPATH=$MANPATH:~/~/jdk1.5.0_06/man
JAVA_HOME=~/jdk1.5.0_06
source the profile once and start the Eclipse IDE:
sh# eclipse
Go to Windows menu and select Preferences from it. Select Java -> Installed JREs from the left pane and click on the “Add” button on the right pane.

Browse to and select jdk1.5.0_06/jre directory from your home directory. Enter “JDK1.5.0_06″ in “JRE Name:” field. Click on Java -> Compiler item from the left pane and select “5.0″ from the “Compiler Compliance Settings:” selection list.

Click OK button to dismiss the dialog box.
Now you can create java 1.5 applications on your Gentoo system using the Eclipse IDE.
Just extract the Eclipse CDT tar file in the eclipse folder to get the C++ support in Eclipse. (contents of ‘features’ directory from downloaded package should go into the ‘features’ directory in eclipse, and contents of ‘plugins’ directory should go into the ‘plugins’ directory in eclipse).
Java on Gentoo
2The simplest way to get started with Java development in Gentoo is to install the Blackdown JDK-1.4.2 along with the Eclipse IDE:
If you want to install the sun’s version of the jdk instead of the blackdown jdk, you can get the 1.4.2 version of it using:
To install the 1.5 version of the jdk, you need to unmask it first. Add the following two lines to your /etc/portage/package.keywords file:
>=dev-java/sun-jdk-1.5.0 ~x86
>=dev-java/java-sdk-docs-1.5.0 ~x86
Now do the emerge:
You can also install both of these versions at the same time, and then make one of them as the default jdk. If you need java support in other applications too(like web browser etc), then make sure to add the relevant keywords in the /etc/portage/package.use file:
=dev-java/sun-jdk-1.4.2.10-r2 X alsa browserplugin doc examples jce mozilla nsplugin
This also installs the documentation and the examples – remove these words if you don’t to install them. Also change the version number if you are installing the 1.5 version of the jdk.
If you want to use Eclipse IDE to create C++ programs, you need the eclipse-cdt plugin. First unmask it by placing the following line in /etc/portage/package.keywords file:
>=dev-util/eclipse-cdt-2.0 ~x86
Now do the emerge:
More information on installing java 1.5 and eclipse 3.x on Gentoo OS.
Recent Comments