Sunday, February 5, 2012

Installing ANT on Windows 7

ANT is popular build tool used in java based application development.

ANT package is not installable binary.  It is .zip file.  I have downloaded latest version, which happens to be 1.8.2. All the instructions below assumed this version.  If you have downloaded some other version, then the version number would be different.

http://apache.mirrors.redwire.net//ant/binaries/apache-ant-1.8.2-bin.zip

Unzip the file into a directory. I  have extracted this into c:\"Program Files".

It gets extracted to c:\"Program Files"\apache-ant-1.8.2\ directory.

You need to do two things before you start using 'ant'.

1. Setting up the environment variable ANT_HOME.   On Windows 7,  it is simple.  Do following steps.
  •  Go to Windows "Start" (Left lower corner windows logo).
  •  Right Click on "Computer".
  •  On the result screen,  click on "Properties".  A new screen appears.
  •  On left navigation panel,  click on "Advance system settings".  If you have logged in as normal users into windows,  it would ask for administrator password.  Give your password.  A new screen titled "system properties" appears.
  • In "Advanced" tab,  click on "Environment variables" button.
  • There user variable can be added with variable name as ANT_HOME and value as c:\Program Files\apache-ant-1.8.2

Second step is to add "c:\program files\apache-ant-1.8.2\bin to the PATH variable.
  • On the screen that results by clicking on 'Environment Variables' button as described above, you can see 'System variables' box.  PATH variable would have been there already.  Double click on it and modify the path variable by appending c:\Program Files\apache-ant-1.8.2\bin.
Verify that above steps are done properly by executing 'ant' command from the command prompt.

  • On Windows "Start",  in "search programs and files' dialog box,  type "command" (no double quotes).   It throws up a command prompt screen.
  • Type 'ant' at the prompt.
  • If it says, it could not find the command,  then there is some issue in setting up the path variable.
  • If it says ANT_HOME is wrong,  then ANT_HOME environment variable is not set.
  • If you find tools.jar is not found error, it means that you did not install the Java SE JDK.  Install Java SE JDK and set the JAVA_HOME environment variable pointing to newly installed JDK.  To set the environment variable, follow the similar steps followed for setting up the ANT_HOME.

Saturday, February 4, 2012

Ubuntu 11.10 - Installing Java 7


Download Java SE SDK from java.oracle.com website.  In my case, I needed to download 32 bit version of Linux. Hence I used this link:  http://download.oracle.com/otn-pub/java/jdk/7u2-b13/jdk-7u2-linux-i586.tar.gz

I downloaded this /tmp directory.

Extract the files first;

Execute this from the ubuntu terminal shell:  sudo tar -zvxf  jdk-7u2-linux-i586.tar.gz
It creates a directory called jdk1.7.0_02 (This could be different based on the version you download).

Now we need to link it at proper place in ubuntu. First move the jdk into /usr/lib/jvm directory

Execute this from Ubuntu shell :  sudo mv jdk1.7.0_02 /usr/lib/jvm

Make the ubuntu know about this java: 

First check if there is any java jdk installed before.
Execute this command from ubuntu shell:  sudo update-alternatives --config java

Above command will list down currently installed java versions and their priorities.  In my case, there were no previous installations of java.

Execute this command from ubuntu shell to make this java known to Ubuntu:  sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0_02/jre/bin/java 1

Above command not only creates a symbolic link at /usr/bin/java and also informs the software manager of ubuntu of the package name "java".   Since it is my first installation of java in this machine,  I gave priority 1 to above command.

Verification;

Check the java installation by executing following commands at shell:
sudo update-alternatives --config java
Above command should show the java you have just installed.

Finally execute following to ensure that the version you see is the one you  have just installed
java -version
Above command prints the java version.


Sunday, December 25, 2011

Downloading and Installing Beacon on Windows 7 - My Experiences

I thought I would spend few days  on understanding the work that was already done in SDN (Software Defined Networking world).  I am very familiar with device side architecture and development tools. I spent most of my time in the job on creating/architecting software required on the network devices - Briding, routing,  L4 switching and even application level proxying device. 

I have written few blog posts on SDN world in netsecinfo.blogpsot.com.   Particularly, I have talked about Java role in SDN in this "Software Defined Networking - Java Role" post. Since I believe that this would be true as and when SDN picks up ,  I thought I would brush my Java skills and make my hands dirty.   As part of that,  I decided to spend some time on Beacon controller which is open source controller developed in Java to control openflow based hardware devices.


Of course, first step in that is to download and install beacon controller and associated development environment.  There is good instruction sheet in beacon site, which talked about downloading source code,  compiling/debugging in eclipse environment and developing new bundles.  I am following that sheet and would give my experience and learning I had during this process in this post.

First step is downloading "openflow" java code as well as "beacon" java source code.  Since I had cygwin installed on my Windows7 laptop,  it just went through fine.
  • I created a directory using "mkdir -p /cygdrive/c/SDN/controller".
  • Changed directory to just created directory "cd /cygdrive/c/SDN/controller".
  • Executed both the steps given in the guide to download the sources.
    • git clone git://gitosis.stanford.edu/openflowj.git
    • git clone git://gitosis.stanford.edu/beacon.git
  • git creates the two sub directories "openflowj" and "beacon" in the /cygdrive/c/SDN/controller directory.
So far so good. Very smooth.

Now to installation of JDK.  First step is to find out what version of JDK your system already has.  It appears that beacon requires Java SDK 6.  Note that, many systems have JRE installed, but not the JDK.  JRE is meant to run the Java binaries.  JDK is beyond JRE.  It is development kit and intended to develop java based applications.

Typically, Java is installed in c:\"Program Files"\Java.  Go to that directory and try to find whether there is any sub directory that starts with "jdk".  The directory itself contains the version number in it.  In my system, I only had JRE.  I installed 64 bit JDK (J2SE SDK) for windows from this web site http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-419409.html#jdk-6u29-oth-JPR.  It is better to start from this site  http://www.oracle.com/technetwork/java/javase/downloads/jdk6-jsp-136632.html to get the latest JDK6.  Downloading requires user account with oracle.

Installation was a breeze. Just follow the steps.  It is good to keep the default installation directory to c:\"program files"\java.  After successful installation, you should see sub directory starting with "jdk".  I see "jdk1.6.0_29" sub directory after JDK installation. The installation also creates "jre6" directory.

Beacon controller based development can happen using Eclipse.  Eclipse is a integrated development environment where the java code can be edited,  compiled, debugged and run without leaving the eclipse.  There are many Eclipse packages, with each package meant to develop certain types of applications.  Beacon suggests to download  Eclipse for RCP and RAP.   RCP and RAP are mainly to develop applications that require Rich Client experience. RCP (Rich Client Platform) is used to develop clients (non-web).  RAP (Rich Ajax Platform) to develop RCP in browsers (Web based).  Single code base can be developed to run applications as native non-web based rich clients or web based software.

Now onto download and installation of Eclipse for RCP and RAP: I selected 64 bit version as my system has 64 bit operating system.  One Zip file gets downloaded. Once it is downloaded, extract it to directory of your choice.  It creates 'eclipse' sub directory and all files get extracted to this.  There is no installation program (setup) to install the eclipse.  Extraction itself is good enough.  You will see 'eclipse' executable in 'eclipse' directory.  You could execute this to open eclipse.

Now that all the required packages are downloaded and installed,  now it is time to compile the beacon and openflow source code and use it.  Start 'eclipse' by running eclipse.exe from the eclipse directory.

Setting the Java compiler compliance level to 1.6:  J2SE 1.5 version is major release which introduced many ease-of-development features (hence java language extensions)  such as  Annotations,  Generic types, Auto-boxing,  Loop enhancements,  Varargs,  concurrency utilities and many more.  JDK 1.6 introduced some more features.  For more information about features added in J2SE 1.5,  check this out http://java.sun.com/developer/technicalArticles/releases/j2se15/ .   For features that were added in J2SE 1.6,  check this URL link http://www.oracle.com/technetwork/java/javase/features-141434.html.

Beacon may be using some of the features introduced in the J2SE 1.5 and 1.6.  Hence it is required to have the java compiler compliance level to 1.6.  To do this,  in eclipse,  click on "window" in top level menu.  Select "Preferences" in window sub-menu.  Expand 'java' in left panel.  You would see "compiler' on the expanded pane.  Click on  "compiler".  On the right pane, you will see "Compiler compliance level". CHnage the value to 1.6 if it is not already set to 1.6.

Import openflowj project in eclipse:  This is simple job too.  Click on "Import" in "File" menu.  It pops up a screen to select the import source.  Select General>Existing Projects into workspace. Select 'Select Root Directory'.  Using "Browse" button,  get the path to openflowj directory.   Click on "Finish".    It imports openflowj project into eclipse.

Do similar stuff to import 'beacon' project in eclipse. In both cases, don't select "Copy projects into workspace".

Once both projects are loaded into eclipse, you would see lots of errors. It is because, the dependency files are not yet downloaded and resolved.  To do this,  just follow these steps.
  • Open the Beacon Main Target project, double click the main.target file.
  • It starts resolving, you can see this in right hand and lower corner of the screen "Resolving to Target Definition".
  • Once it is resolved,  click "Set as Target Platform" on the top right corner of the screen.
  • It is expected that all compiler errors would go away.
  • In my case,  it showed me one error in Routing.java.  I got an error "Uncatchable catch block for CloneNotSupportedException. This exception is never thrown from the try statement body".  I don't know what this error is about.  Just to move forward,  I have removed everything from try and catch and just kept fm = fm.clone(); statement.  Error went away. I need to revisit this and check what is right thing to do here.
  • With above, all compilation errors went away.
Now that the code is compilable, it is time to run.  Run in debug mode.  I just followed the instructions  Select Run>Debug Configurations.  On left panel,  expand 'OSGi".  Select beacon and click on Debug. 

This will also start the web server on port 8080 on local machine. You could see beacon  controller screens by going to your browser and typing http;//localhost:8080 in URL area.

Cygwin - Get Linux feeling on Windows

If  you are like me who moved from Unix/Linux world to Windows, but still comfortable in working with bash shell,  VI, emacs and cscope/ctags for source code browsing,  cygwin is here for you.

I have been using cygwin from 2005 when we moved from Linux based development and desktop systems to Windows. It helped me in transiting slowly into GUI world from command line world.  Though I am pretty comfortable with windows with respect to editing documents,  power point presentations,  emails and 90% of the work which I do at office and home,  I am still comfortable using Cygwin for source code related activities whether it is for understanding the code,  developing the code,  develop some simple proof-of-concepts etc..

Cygwin has almost all development libraries, databases, editors,  servers, client applications which you normally need to use as a programmer.  It is quite rich. Ones which I use normally are -- VI editor,  mlcscope (cscope variant),  ctags,  gcc,  git,  svn,  several compression/decompress  utilities including gzip, bzip and many archiving utilities such as tar etc..  As you may know many of the open source packages you downloads are available in tar.gz (tgz),  tar.bz2 formats.  Hence these utilities come in handy. Also,  as a developer if you need to download latest source code from source code repositories,  one needs to have utilities such as svn, git.  By the way,  git and svn repositories are more popular now than 'cvs'. 

Cygwin is available in here at www.cygwin.com.

Download and install instructions are available at above site.  But, I will try to give some quick instructions on downloading and installing cygwin packages.
  • Look for "setup.exe" link the cygwin home page.  You can also find it in "Install Cygwin" link.
  • Your browser would download "setup" executable and would take permission to run.  Many browsers in recent past have added this addition step to stop unsolicited executables to execute and install without user knowledge.  Since, in this case, we are deliberately downloaded this and executing it,  you can give permissions to run.  If you are running as a Windows user (not as an administrator),  it would ask you to enter the administrator password to install cygwin packages for all users in the system. Go ahead and enter your administrator password. 
  • "Setup" program is a GUI based program with each screen having "Next" button. It is pretty much self-explanatory.  
  • First screen explains that the purpose of this program,  copyright etc.. Clicking on "Next" to move forward.
  • Program asks you to download the actual cygwin packages and install from "Install from Internet",  "Download without Install",  "Install from local directory".   If this is the first time you are running this application,  you may like to select "Install from Internet" and click on "Next".
  • "Choose Install Directory" screen ask for the installation directory.  You can leave the default option, if  you don't want to remember this during future upgrades.  It also asks for you to make cygwin available for all users in the windows machine or only for current user.  Since it is useful for all users, I normally select "All users".   Click on "Next" to proceed further.
  • "Select Local Package Directory" screen asks for cygwin setup/upgrade program to store some information such as installation files. Using this, cygwin setup program knows the cygwin programs it had installed in the system in previous attempts.  I, normally keep the default directory as is.  Click on "Next" to proceed further.
  • "Select Your Internet Connection" lets you choose the way to download files.  If you have no proxies to Internet, which would be the case for many home  users, then select "Direct Connection".  If your machine is behind a proxy,  then it gives you two options - You could ask the setup program to learn it from your IE or you could give the proxy details yourself.  Once this is done, click on "Next" to go to next screen.
  • "Choose download sites";  Cygwin packages are available from multiple sites.  This screen provides all the mirror sites where cygwin packages can be downloaded by "setup" program.  It is difficult to know which site is near you,  but yet times the domain name might give you some clue.  Select the one which you believe could be near you.  Once the site is selected, click on "Next".
  • "Select Packages":  This is the screen which allows  you to select the packages to download. In addition to base package,  I normally select following;
    • Under "Databases", I select postgres related items as yet times I work with databases.
    • Under "Devel",  I select "gcc4" compilers,  ctgs and mlcscope.
    • Under "Editors", I select VIM,  emacs.
  • "Select packages",  you can also search if you know the package name or part of the package name. 
  • Note that you could come back and select some more packages at later time too.  So, if you don't know all the packages you require at this time,  there is nothing to worry. You can upgrade the cygwin at any time in future.
  • Clicking on "Next" would download the packages and installs them. This might take few minutes to 1/2 hour based on a broadband connection.  Once it completes installing them, it would ask you to keep the icon on desktop. "Finish" would finish up the setup program.
  • You would see 'Cygwin Terminal" icon on desktop and also in "Start" screen.

Click on "Cygwin Terminal",  you would see your familiar bash terminal.  

If you want to access the files in your drives on Windows, it is simple.  By default, when the bash terminal is opened, you are in directory called "/home/<windows user name>".    Cygwin root directory is typically starts at the installation directory you have chosen.  If you remember, by default the cygwin installation directory is  c:\cygwin.  

To go to any directory in "C:\" , "D:\" or any drive in the windows,  you can do it by typing "/cygdrive/<drive name>/<subdirectory>.  That is to go to c:\ from the cygwin terminal, you can type "/cygdrive/c" and press enter.  Now, you can see all files in c:\ using familiar bash commands such as "ls".  Another neat thing is that you could execute even your windows executables from the the cygwin terminal.

32 bit / 64 bit operating systems - Windows 7

With 64 bit processors becoming popular,  many open source and commercial packages are being delivered in both 32 bit and 64 bit forms.

Windows 7 operating system itself comes in both 32 bit and 64 bit.

How do end users know which open source/commercial package to download and install? 

That depends on what operating system you have.

In Windows 7,  it is very easy to know whether the operating system you have in  your laptop/desktop is 32 bit or 64 bit operating system.

On Windows 7;

  • Click on Start (lower left corner of you screen).
  • On resulting pop up screen,  click on "Control Panel"
  • On Control Panel screen,  Go to "System  and Security" by clicking on it.  (Note that it appears like heading, but you can click on it).
  • On resulting screen, click on "System" (Again, one might think that it is only  heading, but it is clickable).
  • On result screen, you would see enough information about operating system installed and system information.  Under "System", you would see "System type".  Value of "System type" tells you whether it is 32 bit operating system or 64 bit operating system.