This is the first of many blogs on the Java environment. This shows step by step as to how to install the JDK, JBoss and Eclipse without depending on apt. The exception is mysql. The following blog (part II), will show the user how to install Java Development Stack via apt. I personally don’t like my Java (in both the Linux and Windows) environments, automatically installed by the OS.
You’ve probably read my notes on setting up a LAMP stack on an Ubuntu environment (if you haven’t, read here). The process takes less than hour, depending on your connection speed, hardware resources, etc. Well, from my experience, setting up Java development environment has always been a little “hairy”. Why? It’s because certain application servers are difficult to setup, along with non-Eclipse or non-IntelliJ based IDE’s. For most small to mid sized projects, the requirements are actually pretty small in terms of hardware resources, so an application like Weblogic or WebSphere is pure over kill.
These are my notes for setting up a development environment for Java using free (open and proprietary) sources. Unfortunately, it takes a little longer than an hour, but hopefully, not too much more.
Requirements:
- Comfortable setting up applications via a command line (with sudo privileges)
- Comfortable with apt-get
- Understanding of runtime and container technologies (apache, IIS if your a MS convert, etc)
Downloads (Check the Downloads section below):
- Ubuntu 9.04 (Jaunty)
- Sun’s JDK, version 5/6
- JBoss 5.0.1
- JBoss Downloads from sourceforge
- MySQL 5
- Eclipse Galileo
- 1 PC for your desktop, optional PC for server
- unzip, via typing: sudo apt-get install unzip
Prepwork:
You’ll want to start by setting up your Ubuntu desktop. It’s super easy. Chances are, you already have an Ubuntu desktop, but you may not have an Ubuntu server. Get the 64 bit edition of both.
From here, you’ll have two choices. First, if you only have one PC, make sure it’s a semi beast (min: dual core, 2 Gigs of RAM; recommended: quad core, 4 Gigs of RAM) because both Eclipse and JBoss can be hogs, albeit not as hoggish as the other application servers (Weblogic, Websphere, OAS prior to Weblogic). You’ll have to approach the strategy of 1 PC as both the development environment and deployment environment. If you’re a novice, this may be the route you’ll want to take any way.
Second option is 1 PC for development and 1 PC for your server. For this, you’ll want to download the server edition of Ubuntu. If you’re a novice, avoid this strategy and stick with the first option above. Your first PC, which we will call our developer environment, will be a desktop which will house Eclipse. Your second PC, which we will call your deployment environment, will be Ubuntu server, which will house JBoss and MySQL. Both will have JDK 6 installed.
Note: Ubuntu server does not have a desktop per se. You have to be comfortable with the command prompt, or install a light desktop (like xcfe, however, gnome and kde are too thick, don’t do it).
You’ll want to download the technology stack below. Start by downloading Sun’s JDK, look for a file named JDK 6 Update X where X is a number. Don’t download anything that has ‘NetBeans’, ‘JavaFX’ or ‘Java EE’ on this page. Then download Eclipse (with J2EE) and JBoss (version 5 or 5.0.1 preferred). MySQL can be installed easily via tasksel or aptitude.
Background Notes:
There’s Sun’s JDK and OpenJDK. Both are from Sun, OpenJDK is the open source version. I’ve used OpenJDK for a couple of my hosts, but I do prefer the non open source (but free) version just because I’ve used for so many years. If you choose to use the OpenJDK version, you may have to do additional configuration not available in the scope of this blog.
Another thing to watch out for is that the newer your environments are, the better. You may have applications that only work on legacy versions of java, this is unlikely, but a clean system would ensure minimal or zero conflics.
Lastly, make sure that the JDK and Eclipse are both 64 bit editions.
Step 1: Install the Sun JDK on the Developer Environment
The .bin file, which you downloaded, is an executable. Make sure your permissions are correct before doing so. You will have to agree to an SLA. The result should be a folder. Rename this folder to ‘java’ and move it to your /opt folder. Add this path to your .bash profile in your home or append it to your /etc/bash.bashrc for global use as such (recommended):
- JAVA_HOME=/opt/java
- PATH=$PATH:$JAVA_HOME/bin
You will have to restart your Ubuntu machine, once you do, you know if java works after invoking this command:
- java -version
Step 2: Install Eclipse on the Developer Environment
The Eclipse download is a compressed tar ball with a tar.gz extension. You can untar this by typing:
- tar xvfz <filename>
- where <filename> is the name of the Eclipse file without the <>
Rename the uncompressed folder to eclipse. Since this should not be used globally, you should drop it in: /home/<your_username>. You can make a link to the desktop, or go to the terminal and type in the eclipse folder:
- eclipse &
This will pull up your Eclipse IDE.
Step 3: Install JBoss
I highly recommend installing JBoss in a separate machine if you can. The JBoss 5 download is a zip file (alternative downloads from sourceforge). You should install the unzip application via sudo apt-get install unzip in the command prompt. The result is a folder. Rename the folder to jboss and move it to the /opt folder, along side your jdk. From this point onward, we will call /opt/jboss as JBOSS_HOME, but no need to alter your bash profile or variable exports to reflect this. Some notable folders:
- JBOSS_HOME/bin – the location of the start up script
- JBOSS_HOME/server/default – the location of where you will drop war/ear files
Step 4: Install MySQL server
Easy step. Where ever your JBoss lives, invoke this command in the command prompt:
- sudo apt-get install mysql-server
You’ll have to change a file called my.cnf. You can find it via going to the root folder (cd /) and type:
- find . |grep my.cnf
Then:
- change line: bind-address = localhost
- to: bind-address = whatever_your_ip_address_is
Lastly, type:
- mysql -u root -p
- GRANT ALL PRIVILEGES ON *.* TO ‘your_username’@'*’ IDENTIFIED BY ‘whatever_your_password_is’ with grant option;
This allows your query tool to view/update the data, independent of the machine. DO NOT DO THIS IN PRODUCTION ENVIRONMENTS!!!!
Note: You have to decide what your query tool is for mysql. I prefer MySql Query Browser which can be downloaded here. Others, prefer Tora.
Conclusion:
You now have the minimum resources to develop in Java with a nice application server and a nice database. The next step is to actually write an application based on JSP’s, servlets and JDBC. The a later blog, I will let you know how to do that. It’s pretty simple really.
Meanwhile, acclimate yourself with the Eclipse environment. Read up on writing war applications and deploying it to JBoss with ant. I hope this helps.
Optional Tools:
- subversion – version control which is better than cvs, but a lot of people are starting to use git
- ant – most popular ‘make-like’ tool for java developers, an alternative is maven but not recommended unless you have a huge project.
- subclipse – a subversion interface for Eclipse, great tool
References:
- http://jboss.org/
- http://www.mysql.com/
Downloads:
- JBoss
- Eclipse Galileo
- Ubuntu Desktop
- Ubuntu Server
- Sun’s Java JDK, version 5 or 6, preferably 6
PraLkHeadyLer said,
December 11, 2009 at 2:41 pm
Wow enjoyed reading this post. I added your rss to my google reader!!
koolaborate said,
December 12, 2009 at 6:30 pm
Thank you, PraLkHeadyLer.