Setting up Java Development on Raspberry Pi

The idea of using the Pi as a machine for java development really excited me. With 8GB ram and quad core arm 64 bit processor and Manjaro Mate as the operating system, it was more than capable of running necessary apps for Java development. I was willing to see how far I can go with this. At minimum I was looking at installing JDK 11, maven, an IDE like IntelliJ and try to run some sample code.

I turned to the trusted sdkman. Installing sdkman was a breeze and few quick commands helped me install java and maven as well.

curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
sdk install java 11.0.16-zulu
sdk install mvn 3.8.6

Time to check if everything is installed correctly

[koolksp@koolksp-rpi ~]$ java -version
openjdk version "11.0.16" 2022-07-19 LTS
OpenJDK Runtime Environment Zulu11.58+15-CA (build 11.0.16+8-LTS)
OpenJDK 64-Bit Server VM Zulu11.58+15-CA (build 11.0.16+8-LTS, mixed mode)
[koolksp@koolksp-rpi ~]$ mvn -version
Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Maven home: /home/koolksp/.sdkman/candidates/maven/current
Java version: 11.0.16, vendor: Azul Systems, Inc., runtime: /home/koolksp/.sdkman/candidates/java/11.0.16-zulu
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.15.56-1-manjaro-arm-rpi", arch: "aarch64", family: "unix"
[koolksp@koolksp-rpi ~]$

For the IDE, IntelliJ IDEA version for linux is a downloadable .tar.gz file. Simply extracting it and running the idea.sh script brings up the IDE. I had to tweak a few system variables and set the PATH for things to work. But once done I had no issue starting the IDE. I quickly created a maven project, added some sample code and went ahead with maven build to create a jar file. Running the code within IntelliJ shows output as expected. Of course it is not blazing fast. Pi does have its limitations, but the fact that it can indeed do all this is a feat. The small single board computer does pack a punch. It will be fun to have some small project developed and tested on the Pi. I plan to extend my dev setup to include spring boot and maybe a tomcat server, just to see how far I can push this tiny beast.

Speed Up Your Dev Setup With Sdkman

How often has it happened that you move to a different project and are provided a new machine to work on? However exciting it may make you feel, the thing that you dread the most is lurking just around the corner. The next immediate task that you are expected to do is setup the damn machine with your usual bells and whistles before you can even start writing a single line of code. The same is true if you managed to swipe out the OS from your laptop and start putting the bits and pieces all over again. The entire process isn’t difficult or near impossible for an advanced developer, but it is better if we label this activity as a waste of time and only wish if there were ways to speed it up.

This is the void which sdkman fills. And I have grown to like this approach to setup my machine. Head over to the sdkman homepage and you will realize what I am trying to say.

Installing sdkman on Linux is a breeze. Just fire up

curl -s "https://get.sdkman.io" | bash

and follow instructions on the screen.

Once sdk in installed, its just a matter of few more commands to quickly have a working dev setup up and running. sdk has a list of handy commands which are listed below

sdk list – lists all the different software development kits available for installation including jvms for java.
sdk list [name] – lists all versions of the required sdk eg Java, Maven, Gradle etc
sdk install [name] – installs the latest stable version of the required sdk
sdk install [name] [identifier] – installs the specified version of the sdk, in case you wish to use an older, more specific version.

Armed with this knowledge lets see how I proceeded to setup a dev machine. First activity ofcourse is to install a jdk.
sdk list java will list out all versions from all vendors available and provide identifiers which we will use when proceeding with installation. So say we wanted to install java 11 from AdoptOpenJDK the command to install it would simple be sdk install java 11.0.4.hs-adpt by using the identifier for installation.

List of available versions with indentifier for installation.

Some linux flavors come with openjdk preinstalled, in which case the step to install java can be skipped.

Moving ahead to install other things was simply invoking the following commands

sdk install gradle 5.5.1
sdk install maven 3.6.1
sdk install springboot 2.1.7.RELEASE

sdk manages adding these libs to be path and making sure developers don’t need to mess with the settings and thus making their life a bit easier.

sdkman documentation says it runs on any UNIX based platforms: Mac OSX, Linux, Cygwin, Solaris and FreeBSD. But as a hack, I found this to work on Windows as well using the Git Bash. The only issue was git bash does not have zip executable which is required for installing sdkman itself. As a workaround, since I had 7zip installed on windows, I simply made a copy of 7z.exe, renamed it to zip.exe and made sure this file is on the git bash path. This fooled sdkman into thinking the required dependencies exist and it went ahead without any hassle.

Then all that is left is to install any IDE like IntelliJ and/or text editor like sublime text and trance away into coding heaven.

GitKraken : Control your source in style

I picked up Git quite some time back and have come to love its features. In todays coding world knowledge of git is really a must have skill. Yeah you have worked with different source control systems before but having a distributed version control system means you can work in complete isolation and then merge the code only when collaborating with other members in the team. Git works even better for someone working individually where having a dedicated svn setup for just one person making all the check ins is an overkill. But lets face it, using git from the command line is quite cumbersome and no matter how hard I tried, I never got to the point where I was comfortable with the git UI clients native to Linux.

That was until I discovered GitKraken. Their site describes GitKraken as a downright luxurious Git client. Just download the client for your OS and you will realize what they are talking about.

It is a cross platform, free, standalone client, meaning you don’t even need to have git previously installed on your system. Just install GitKraken and you are good to go.

At start it will prompt for setting up the user name and email. These are set as the global config values in git. A few quick settings and you are done.

This slideshow requires JavaScript.


You can init a repo by either of the options. It could be a local git repo for a remote repo on bitbucket or github. Other options are to open or clone an existing repo.

Screenshot at 2016-06-04 22:47:51

Once you are working with an existing repo, GitKraken keeps track of the file changes and gives you a simple intuitive way to manage your staged/unstaged files and check in files that are relevant to the code changes you are working on. The window pane on the right of the UI lets you handpick files that you want to commit and give appropriate comments before checking it in.

Screenshot at 2016-06-04 23:21:57

 
History of changes appears in the center pane of the UI and it allows you to search through the check ins made so far. All this makes working with git really very simple with few mouse clicks and visual cues.

The left side of the UI shows whether you are working on the master or a branch and creating or deleting branches is again just a matter of right click. Right click menu on the branch gives you several options to push/pull code from remote, or create/delete branches or pick specific files for commit etc. It all much more easier than remembering the git cli commands. Common actions are also accessible via the overhead ui toolbar.

Screenshot at 2016-06-04 23:41:03

Screenshot at 2016-06-04 23:21:57 (copy)

Merging/rebasing branches is even simpler. After working on the changes on a branch, when you are ready to merge it back into master just drag and drop the label on the UI and GitKraken will provide options in the menu.

Screenshot at 2016-06-04 23:08:57

GitKraken team have done an awesome job. No wonder they call it downright luxurious since they have pulled off something quite magical here. Things just happen. With such an intuitive way of working with your source control, who wouldn’t want to keep using it. After years of dabbling with cli commands, I am more than ready to welcome GitKraken into my coding realm.

Unleash the power of Sublime Text

A while back, I evaluated Sublime Text and its suitability for code development; be it simple scripting in Unix or Python or some basic code development in Java. It is indeed a powerful editor with support for lot of languages like HTML, CSS, Javascript, Python, Ruby and I could go on. Though not a full fledged IDE, it still packs enough punch to get by your development needs. And which is why I am revisiting the latest version of Sublime. The current version under evaluation is Beta 3 Build 3103.

The real power of Sublime lies in the extensible packages that users can install and make it more productive. Its not just about editing your code any more, but with aid of useful and productive add ons you can make the best of your coding work flow all while working within Sublime. This article aims to discuss these things and how you can unleash the hidden power of Sublime Text.

The first thing to do after downloading the latest version of Sublime Text 3 is to install the package control plugin which allows you to quickly find and install other plugins. After successful installation, the installation menu can be activate by pressing [Ctrl + Shift + P] and typing install in the text box. Package control has a list of repositories which it looks up and lists several plugins to choose from. Search and install the plugin that you like from here.

Package Control gives you access to numerous themes and color schemes which you can install to change the default look and feel of your Sublime. I went ahead with the Soda Light theme and Cobalt color scheme. The colors go well with my Openbox themes on LXDE. Other cool themes worth checking are Minimal, Seti-UI, Spacegray and Brogrammer among others. The sheer number of color schemes and themes for Sublime Text is as ever increasing one, so go ahead and tweak it to your heart’s content.

Another worthy upgrade to do is install the Sidebar Enhancement plugin. This gives more options to the user when using the right click menu on the side bar where all files are visible under their folders.

After some cosmetic changes, I am going to turn towards code development. For your html coding needs Emmet is an excellent plugin. It allows for auto completion of tags which makes editing a breeze. That along with smart editing short cuts of sublime will make for improved productivity for front end coding.

Bracket Highlighter is a cool plugin which quickly tells you position of the closing brackets and displays this information in the gutter besides the lines numbes. That way it is easy to locate locate relevant code in json, java, javascript, html and many more.

One of my purposes to using Sublime is coding in Java and while I could write java code in a notepad application as well, it helps to have some auto completion features and project management. I installed JavaIME for this and also Javatar plugins. Both provide sufficient features to get by coding in Java. These arent a replacement for any IDE by any means, but having these plugins help a lot.

And I think these can be better complimented by plugins for maven so that you can build the project within the Sublime window rather than going to the terminal everytime. Maven plugin also adds useful shortcuts to the side bar enhancement menu which can help manage project workflow from the UI.

No developer can live without some kind of version control. Luckily you have good support for both git and svn. For git, GitSavvy gives all the power of git from within the sublime menus. And for svn, I found tortoise svn plugin very useful on windows platform. It just needs to know the location of locally installed tortoise executable and the plugin then delegates the svn commands to the tortoise executable. While using git, GitGutter is another useful plugin, which promptly highlights the changes in the current file against the last checked in changes. This makes it easy to identify changes and commit them while you are working with the files.

I guess this is where I stopped for a while and looked back at how all these plugins can fit well in your workflow. Assume you are working on a java project, you could quickly create an empty maven project outside of sublime using archetypes. Open that folder with sublime and you have a project structure to work with, use Javatar plugin to configure the java build paths and source folders. Use maven as your build system, so that you can build and package your java project. After making source code changes, you could use either git or svn to do appropriate source control of your project.

With these plugins installed, Sublime Text definitely transforms into something more than a text editor. It makes your workflow more stream lined and gets you going with the awesome code that you want to develop. Who knows, with enough familiarity of all the unleashed power of Sublime,  you could just kiss your favorite IDE good bye.

Quick Conversion from m4a to mp3

With youtube-dl, I have a very handy solution to rip off some quick audio from youtube videos. I wanted to listen to the ripped audio files during my drive to work and back. But my car audio system refused to recognize the m4a file extension and begged me to feed it some mp3 files.

And so I was left looking for some solution to quickly convert m4a files to mp3 format. There are utilities available out there, but I thought it would be cool to use some command line for this. So I wrote a small script to help me out.

This uses the ffmpeg library to convert all m4a files in the current directory and encodes them into mp3. The script is shared below.

#! /bin/sh

if [ ! -d newfiles ]
then
mkdir newfiles
fi

filecount=`ls -1 *.m4a | wc -l`
currdir=`pwd`
echo “Batch converting “$filecount” m4a files in folder : “$currdir
read -p “Press any key to continue…”

for f in *.m4a; do ffmpeg -i “$f” -codec:v copy -codec:a libmp3lame -q:a 2 newfiles/”${f%.m4a}.mp3″; done
clear
echo “Done… check these files”
echo “**************************************************”
ls -1 newfiles/*.mp3
echo “**************************************************”

‘Tide’ packs a punch!

I have been using Eclipse at work and IntelliJ Idea at home for quite some time and find both very good. But do you really need a full fledged IDE when you are just trying out some basic java code or samples which dont run into hundreds of lines of code. You could very well use some notepad app for that, but would still miss things like adding external libraries, compiling and running your main program quickly etc. You would definitley need some basic ide without much fuss.

Just out of curiosity, I started looking around for a light weight IDE for java and TIDE popped up on google. Commentors on forums urged to use this one as it was very simple and small to get started, no installation required and works well for pure java projects. Sure enough, the entire application is only a jar file just under 4MB. Now thats impressive. I downloaded the jar from sourceforge and got started with it.

Fired it up using command

java -jar tide.jar

and there is was, a tiny IDE at work! It asked for basic configuration like project location, jdk installation location etc and in few quick clicks I was ready to go!

The interface is very simple and functional and themeable with tabs for different things like the console output, compile messages etc. Creating and editing packages and classes is quick and without a fuss. The tiny ide has excellent menu items useful for setting up projects, configuring and running applications, support for external tools like ant, git, subversion, PMD, findbugs etc. So if you depend on either of these for project work, you can enjoy the support this IDE provides.

I was able to setup a small project and execute it in no time. Tide also provides for class templates and autocompletion capabilities which you can extend and add some more of your own. The only down side I encountered was that the ide is purely for java, so much so that the only files I could create or edit were java classes. I found no way to add an xml config file, or a properties file in the project, which kind of defeats the purpose of an ide, but you can always add/edit these files externally. Opening the project location as a directory in sublime will support this very well.

Screenshot from 2015-02-21 00:06:25

What suprises me is that the developer has packed in so much functionality and third party support into this application and made it available as a runnable jar which does not really need any additional setup to run. This definitely come as a boon for less powered machines which may find it heavy to run eclipse or idea. So if you are low on resources or cant spare much memory Tide would be a good fit.

To be able to run tide from the command prompt, I tried a little hack and seems to work perfectly. I created a shell script to launch the jar using the above command and added an ampersand sign to it. so contents of the script are like so

java -jar /path/to/my/tide.jar &

This will execute the java code and set it as a background process in linux, this frees up the terminal and you can continue working with something else.

Also I created a softlink inside the /usr/bin folder using sudo rights and point it to my script which in turn launches tide.

sudo ln -s /path/to/script tide

This hack now allows me to execute tide from anywhere on the prompt, and it fires up the teeny tiny ide to get on with some quick code. Try it out, you’d be impressed!

IntelliJ Idea’s Git Integration Makes It Simpler Than Ever

Since the last post on Git, I have been making myself familiar with UI tools which will make the job mush easier. git command line is powerful no doubt, but when working on some project or within an IDE, it sometimes may become cumbersome to keep switching between your work and the terminal to check the changes in. I also came across some git UI clients like gitk, gitg but somewhere the functionality didnt seem complete and cli still reigned supreme. I was looking for a really simple way to get more productive with git without the hassles of going back and forth on the terminal.

The answer was right in front of me. IntelliJ Idea, the Java IDE I chose to install on my machine already has an excellent integration with git. And all I had to do was make myself more familiar with how to use it while working. In fact I would say that with git integration that Idea provides, no one would ever be hesitant to quickly embrace git in their daily coding routine.

To illustrate this, let me start with some dummy project. GitDemo is what I have named it and started adding some code (Hello World it is!) to the project. This is still just a simple project and I havent used git so far. Action begins the moment we add this project to git by initializing the git repo. git init is the cli command, but on IDEA interface this is as simple as selecting the opton from the menu. VCS >> Import into Version Control >> Create Git repository as illustrated in the screen shot below. This will prompt for confirming the directory location for creating the git repo. This selected directory ( the root for our project ) will house the .git folder and wala! our git repo is initialized.

Screenshot from 2014-11-22 13:28:47

Screenshot from 2014-11-22 13:33:44

After initilizing the repo, you carry on as usual and add the root directory to gits staging. This is also available at right click of the mouse. Select project root, right click and select Git and then select Commit directory. This will open up a dialog box to select and commit several files in one go to the local git repo.

Screenshot from 2014-11-22 13:30:10

Check the change history on Idea.

initial-commit history

Lets say we have to branch the master to a new branch for adding some new feature, the cli would be a simple git branch -b new_feature. Via UI, we would do the same thing but finding the Branches Menu under git. This is available on via the VCS menu as well. It asks for a new branch name, create that branch and switch to it as well.

create branch menu

new branch name

Let say we add some more code, on the branch of course and commit it. The changes are still in the new branch and not on master.

Switching back to master will show us that the code on master is indeed older and probably we need to merge the new changes back onto master.

We will do this through a series of steps.
1) Adding new code to branch and commit it

commit on branch

2) Checking out master by selecting it from the list of branches available on the repo. Note that revision history on master is still old. It does not have the feature change we made to the branch.

cehck-out-master

changes not on master yet

3) Merge the feature branch into main.

merge branch to master

select branch to merge

After merging changes to master, we can go ahead and delete the branch that we just created. The only care to be taken here is checkout master and then attempt to delete the feature branch. You will not be able to delete a branch that you are already working in.

delete prev branch

Git UI within Idea has been dead simple so far. Sometimes it complains that it did not find any changes to commit etc. The remedy for that is to use the Synchonise project option on the menu. This refreshes the list and new files that are eligible for commit are now visible.

All said and done, we are at a position now where we can push our changes to a remote repo on github where we can share the project with others. Under the Git Repository menu, we have an option of ‘VCS Push’. It simply means that the current changes in the local git repo need to be pushed to remote. The UI however does not list any remote location. We need to create one and add it to git for this option to work.

push no remote

Creating repository on github.com is simple. If you have a registered account, login and select “New Repository” from the github inteface.

github-repo-create-2

create github repo

Once created, github also provides a set of commands that we can use to add this remote repo to our git config.
git remote add origin https://github.com/koolksp/gitdemo.git is the command of interest here, and needs to be executed on the terminal to add the new git repo as remote. This feature isnt yet available on UI and seems to be the only time when I had to visit the terminal.

After adding the remote url, the option for ‘VCS Push’ shows the outgoing changes and after a successful push we can observe these on github as well.

push origin master

see code on github

see code history on github

And that is how we are quickly through with a simple git enabled project, where we could create repository, branch and merge code for required feature changes and push the final codebase to github by adding a remote repo.

If someone else needed to work with this code now, they would have to clone the url and get started with it! Idea also has option where you can clone an existing git url rather than starting on an empty project. Go ahead give it a try!

My aim here was to get productive as quickly as possible with a new setup of git and IntelliJ Idea. And try and use git via the ui tools rather than cli at the terminal. Either ways getting to know git better makes me more comfortable with it and confident that I can start using it full time with some live project soon.

Git it!

No sooner have you started with your project and the code starts to grow beyond the basic skeleton of folder structures, you come across the need to do some version control for your source code. Rudimentary approach of making backup folders by date or patch files has its fair share of issues when it comes to maintaining the code or going back to specific change you made a week back, while retaining much of the latest changes. Version control gives you a finer control over things, you can keep adding changes to files that you have and the version control tool will give you ability to go back and revert changes whenever required. Most people are familiar with Subversion as an excellent tool for version control and I am sure they all have heard of Git as well, but havent really moved on to it for vairous reasons.

Git has become wildly popular as the tool for version control. It is the brain child of Linus Torvalds and the fact that it is currently used to version contol the linux kernel, which is probably millions of lines of code and the biggest open source project of its kind, speaks leaps and bounds about the capability of Git. It is largely command line driven but several good (and free) clients are also availabe for you to try. It differs from Subversion in the fact that it is a distributed version control system, as against the single server model of svn. At any given time, the git repo on a single machine is all you will ever need to work with the source. These changes can later be moved to , merged into or pushed to other code repositories as and when they are available. So to continue with some work, you need not rely on any central location for making the latest code available to you. Thats sweet!

I have always been a Subversion user, primarily because work never demanded switching to Git ever. So the only option was to start using it with some pet project and understand how it works, how it differs from svn etc.

Over time I think I have a better understanding of git. One can learn it by drawing some parallels between git and svn, but that only creates more confusion since the idea is to understand git as a distributed version control and by comparing it with svn, we kind of miss that point.

Initializing a git repository
There are three ways of achieving this. One is to initialize a new git repository (repo for short) in whatever folder you are in and start maintaining code in there. Second is to clone git code from some local folder that already houses a git repo. Third is to clone git repo from sevaral public git urls hosted on github. This is a location where projects are hosted in public domain and people can collaborate by cloning the repo, contributing their changes and pushing the change back to public repo.

git init - Creates a git repo in current directory.

git clone /path/to/project - clones existing project and starts git repo in current directory

git clone [git-url] - clones a publicly hosted project onto local disk. creates a directory of the same name as the project

Starting to use git
Once the git repo is created, you can carry on with work as usual and then check in the code when done. The key difference here (from svn) is git has a two step commit process. It has a staging area and the actual commited code which are treated as separate things. So for some change to be commited, it has to be added to stage first. Adding to stage simply means git is now tracking those files for change. Files that are not in stage are not tracked and wont make it to repo on commit. git provides simple commands to add, check and commit the changes. In case you missout something during an initial commit, git’s commit command also has an amend flag which will make your change as part of last check in.

Git has branch names for code that you are working with. The default is the “master”, something similar to trunk in svn. You will be able to create new branches and name them as per your convinience. We will see this later.

git status - lists files that have changed since last commit or ones which haven't yet been added to stage

git add [ filename | file1 file2 file3 | *.txt | * ] - start tracking files, use multiple file names or wildcards to add more than one file at a time

git commit -m "message" - commit the changes to current branch. "master" in this case. and add a message for the commit

git commit --amend - Commit this change as part of last check in. This can be used to change comment description, add missed out code etc.

git show - shows files that were checked in the last commit

git show --name-only - will list just the file names and leave out other details.

Before commit, it is usually better to add some config information to git repo. This identifies you by a username and email and this info is added to every commit that you do.

git config --global user.name "Your Name"

git config --global user.email you@yourmail.com

Note that this commit is only on the local master, and is good only if you are the only user of the codebase. If this needs to be shared with others, it has to be send out to remote repository. For this simply add a remote repo to current git setup and push code to external url.

git remote add [remote-name] [git-url] - This adds a repo url identified by the given name

git fetch [remote-name] - fetches all code from the remote location to current directory.

git push [remote-name] master - pushes all local changes in master to the remote repo identified by given name

Branching and Merging
As with other version control tools, you may need to branch out existing code to try out experimental code or add some feature to see how it integrates with rest of the project. git has branches for this. git also allows you to switch between branches, so that the directory in which you are working currently shows only the code which belongs to the branch you are working on. If you switch the branch half way, the changes you made a while back are no longer vsible since you are on a separate branch now. The changes, if committed, will still be on the other branch, so dont worry about it. “branch” command lists all branches in current repo. The default branch is master. You can switch to a different branch using “checkout”. Merging is also simple enough. It merges changes from the mentioned branches into current branch. If all goes well, you have the changes in current branch. The other branch can be removed if no longer used

git branch - lists all branches in the current repo

git branch [branchname] - creates a new branch of given name from current branch

git checkout [branchname] - swicth to branch of given name

git branch -b [branchname] - shortcut command for creating a new branch and switching to it as well

git merge [branchname] - merge contents of given branch into current branch. For this you have to be outside the branch you want to merge. If you try to merge a branch onto itself, git wont complain. It will only say that the branch is "Already up-to-date."

Tagging
So we have done a lot of work and changes on current code and current state of the project is good enough to push out a alpha build say. git provides a way to tag the code base for furture reference.

git tag [tagname] [commit id]

commit id is maintained in the git log, which we can refer for entire list of changes done on the project so far. git will tag code changes identified by the commit id.

Using git in a team
All git commands seen so far work well if you are the only one working on the code. What if you and another friend are collaborating on the project and need to be aware of the code changes made by each other. This is where you need to understand gits way of working with distribute code. git allows you to pull changes from a location and push changes out.

git pull [remote-repo] - gets latest code from the origin (the public git location)

git push [remote-repo] master - pushes code changes from master branch to origin (share changes with other) This is possible after adding a remote repo to your project as we have seen in earlier section.

Once you have latest code with you and start making changes, but need to discard your changes and replace them with the ones on the repo, git can either checkout the individual file again and thereby replace the local copy, or fetch everything from the origin branch and revert all local changes in one go. Be careful when using these options.

So far so good. Feel like a Git Pro already? Things can be confusing, so I made myself some easy to follow charts outlining different git commands that I’d use when working on different scenarios in a project. Apart from the usual commit and reverting of changes, we also have to deal with branching and merging and pushing code to public repo. These small (hastily made) charts will help keep things in perspective. A picture does speak more than a thousand words.

Simple git Initialization
git_init

Clone a project and work on it
git_clone

Revert some local changes
git_revert_local_changes

Basic branch and merge
git_merge

Tag version of the project
git_tag

In course of learning new things about Git, I stumbled upon some excellent reference materials which are worth mentioning here. Further study of these resources will help gain a better understanding of Git. The book “Pro Git” is definitely on my reading list.

1) http://rogerdudler.github.io/git-guide/ – A much better guide than this article
2) http://gitref.org/ – A good reference guide by the GitHub team
3) http://git-scm.com/book/en/v2 – The Pro Git book

There are couple UI tools to work with git as well. I havent started using those yet, as I still need to make myself comfortable with git command line. Maybe a post for Git UI clients can soon follow. For now, hope this quick guide to Git helps understand the concepts and basic usage!

Sublime Text : Gem of an editor

I never really liked editors on linux. vi was my nemesis when it came to editing on command line. I would never voluntarily work with it. Thats a promise I made to myself and abide by it. The cumbersomeness of vi was taken away by nano. I have come to like its features. Its comfortable to work with and doesnt make file editing a daunting task for me atleast.

With the need for better sophisticated editors, more applications started making their presence felt on the linux platform. Of these Sublime Text has really caught my attention. It is a powerful editor with built in support for several languages, which makes it very easy to use as a programming editor on linux. It isnt a fullblown IDE, but salient features like language syntax support, managing folders as projects and defining build systems as per the language you are working with makes it easy to use. It also has a mini map feature on the right side which is a birds eye view of the document that you are working with. Quick mouse clicks can take you to the relevant section that you want to edit, making it easy to handle lengthy config files, huge code etc.

I played around with language support for Python and Java for a while. I could open my earlier maven project with Sublime and work with the files as a regular IDE. The java syntax coloring helps. It also has code assist features which helps add template code for java classes, functions, loops etc making editing a breeze. It can also compile classes for you using the build option.

Screenshot from 2014-10-17 09:46:36

I could also run some sample Python code using the build defined in the menu options. Pressing Ctrl + B to invoke the build, immediately executes the code in current file and the output is shown in the pane below. It makes it easy to identify code errors, fix them and see how your code behaves.

Screenshot from 2014-10-17 10:06:06

With things I have seen so far, I think I am hooked to Sublime. Not to mention great degree of customization thanks to the themes developed by people for Sublime Text. Color Sublime has a huge list of themes, which change the appearance of Sublime and make work more fun.

And just to demonstrate use of Sublime, this blog was written in it. Gives a nice minimal interface to work with and focus on only the editing work at hand. It also has a full screen mode which takes away all unnecessary distractions from your sight. So you work only on what matters. Sublime is really gem of an editor.

Screenshot from 2014-10-17 10:12:16

It is not free though, continued use of Sublime will require you to purchase a license. It occasioanlly nags about it and asks user to buy. But there is currently no limit to evaluating the editor and you can ignore the warning for a while. Though it would make sense to buy if you plan to use Sublime for all the editing needs.

Setting up Artifactory as a Maven Repository

For the uninitiated, Artifactory is a repository manager that integrates really well with host of build teachnologies like ant, maven, gradle. Setting up a local maven repository may not make sense for an individual developer, but it can certainly cater well to small to medium sized teams. A quick introduction screencast video on artifactory website got me curious to check this out.

Setting up Artifactory on linux machine was simpler than I thought. Just download the zip file from official site, extract the contents and run the script file to start Artifactory. Thats all. Artifactory has a web interface that allows user manage settings, repository configurations etc. More on that later.

Screenshot from 2014-10-08 09:57:58

To login as admin, use default username/password as admin/password

Alternatively the Artifactory can also be setup as a service. Just need to execute the installservice script as root. The script is available in the bin folder of install location.

sudo ./installService.sh

This makes Artifactory available as a service and can be used like one. To check status, or start / stop script use following commands

service artifactory [ status | start | stop ]

Thats as quick as we can get to have a working Artifactory instance on a dev machine. Next up is how to integrate this with Maven. By default, maven will look to resolve its dependencies by trying to find them on repo1.maven.org. To setup maven to look up these artifacts on Artifactory we need to tweak the settings.xml file found in .m2 folder. If one doesnt exist yet, artifactory has a settings section which allows users to quickly create one. On the Artifactory UI, click on Maven settings under Client settings. The Maven Settings Generator has few options that user can tweak. The defaults are sufficient for local use. Click on ‘Generate Settings’. This creates a default settings.xml file which can be dropped into the .m2 folder. Maven will now look for artifacts on the local instance of artifactory which in turn would get the artifacts from repo1.maven.org.

Screenshot from 2014-10-08 09:58:22

Executing maven commands on a local project now will show console output similar to the one below. This implies the artifactory setup in now in place and well integrated with maven.
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------------------------------------------------------
[INFO] Building maven1 0.0.1-SNAPSHOT
[INFO] ---------------------------------------------------------------------
Downloading: http://localhost:8081/artifactory/plugins-release/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom
Downloaded: http://localhost:8081/artifactory/plugins-release/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom (4 KB at 1.5 KB/sec)
Downloading: http://localhost:8081/artifactory/plugins-release/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.jar
Downloaded: http://localhost:8081/artifactory/plugins-release/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.jar (25 KB at 23.9 KB/sec)
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ maven1 ---
[INFO] Deleting /home/koolksp/Dev/IdeaProjects/maven1/target
[INFO] ---------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ---------------------------------------------------------------------
[INFO] Total time: 5.626 s
[INFO] Finished at: 2014-10-08T10:00:47+05:30
[INFO] Final Memory: 6M/71M
[INFO] ---------------------------------------------------------------------

Here the required artifacts are supplied by the artifactory’s repository. For a team for several developers, it makes sense to setup a artifactory maven setup and source their dependencies from it, rather than individually managing them from maven repos. This also makes artifact sharing within team members effortless and painless. For instance, say a library developed by one developer needs to be used by another. Since it is not published to maven yet, the second developer has little option but to manually make the library available in his m2 repository and continue with his development activities. Also if the library itself is in active development and more changes are anticipated, the second developer has to keep maintaining newer versions locally, losing on precious time, rather than working on his own code.

Artifactory will work well for both here. A stable release of some library can be deployed onto Artifactory, which is then available for other developers to work with. All they would need to do is add the proper artifact and version to their respective pom xml files.

To illustrate deployment of artifacts, I am going to run through my sample project again. The maven properties for this are

<groupId>com.sample</groupId>
<artifactId>maven1</artifactId>
<version>0.0.1-SNAPSHOT</version>

I do a mvn clean install and find that the generated jar is available at location ~/.m2/repository/com/sample/maven1/0.0.1-SNAPSHOT/. When I check the same on artifactory repository browser, I do not see the jar! The reason being, maven installed the jar into its m2 repo, but has no configuration information to publish an artifact to Artifactory.

Screenshot from 2014-10-16 08:55:11

For this we need to set up the distribution management for Maven. Artifactory manages local releases into separate repositories. So we have a libs-release-local and libs-snapshot-local repositories which need to be set up with maven to get deployment working.

Screenshot from 2014-10-16 09:30:11

Add the distribution management section from artifactory to project pom. Change <id> value to something suitable. Now go to .m2/settings.xml and edit the servers section to add a server configuration with username password and id. This is the same id as configured in distribution management. I am adding two configurations for artifact distribution to snapshot-local and release-local repositories.

So the distribution management section of the project pom looks like so

<distributionManagement>
<repository>
<id>releases</id>
<name>koolksp-3000-N100-releases</name>
<url>http://localhost:8081/artifactory/libs-release-local </url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>koolksp-3000-N100-snapshots</name>
<url>http://localhost:8081/artifactory/libs-snapshot-local </url>
</snapshotRepository>
</distributionManagement>

and the settings.xml reflects this as

<servers>
<server>
<username>admin</username>
<password>password</password>
<id>releases</id>
</server>
<server>
<username>admin</username>
<password>password</password>
<id>snapshots</id>
</server>
</servers>

Now doing a mvn clean deploy uploads the snapshot release to the libs-snapshot-local repo.

Uploading: http://localhost:8081/artifactory/libs-snapshot-local/com/sample/maven1/0.0.1-SNAPSHOT/maven-metadata.xml
Uploaded: http://localhost:8081/artifactory/libs-snapshot-local/com/sample/maven1/0.0.1-SNAPSHOT/maven-metadata.xml (766 B at 32.5 KB/sec)
Uploading: http://localhost:8081/artifactory/libs-snapshot-local/com/sample/maven1/maven-metadata.xml
Uploaded: http://localhost:8081/artifactory/libs-snapshot-local/com/sample/maven1/maven-metadata.xml (312 B at 3.3 KB/sec)
[INFO] ---------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ---------------------------------------------------------------------

The snapshot release is now available on artifactory.

Screenshot from 2014-10-16 08:56:37

Final releases will go into the libs-release-local repository.

Hope this gives sufficient insight to start using Artifactory for all dependency management needs for an individual as well as team of active developers.