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.

Get on with Java

So I kickstart my “Programming on Linux” series with Java. I guess Java installation is quintessential to software development. There are bunch of other tools that in turn depend on Java for their working. eg Groovy, Jruby etc.

Installing Java on linux is pretty straightforward and simple. For most development needs Open JDK installation would suffice, unless you require vendor specific JVMs to be installed.

Quick cli command sudo apt-get install openjdk-7-jdk will install java on the linux machine. If you need only the runtime environment type in sudo apt-get install openjdk-7-jre

Check if java got installed correctly

koolksp@koolksp-3000-N100:~$ which java
/usr/bin/java
koolksp@koolksp-3000-N100:~$ java -version
java version "1.7.0_65"
OpenJDK Runtime Environment (IcedTea 2.5.1) (7u65-2.5.1-4ubuntu1~0.12.04.2)
OpenJDK Server VM (build 24.65-b04, mixed mode)

For the latest and the greatest version, just make sure you have the right repositories setup on linux machine.

For a suitable IDE, I am going to settle with IntelliJ Idea Community edition. I have been an Eclipse user for as long as I can remember, but Idea is equally popular and promises good support for Groovy and Gradle which I am keen to learn. So it solves multiple purposes. It also has good integration with maven, git, svn. Knowing another IDE equally well will serve me good going ahead.

I downloaded Idea from the offical site, and installing it was as simple as unzipping the contents. Find and execute the bin/idea.sh shell script to start the IDE.

Exploring Idea will take its own time I guess, and I may not have to unlearn anything to pick up things that are specific to it. I could quickly put together a maven project with a basic class and a supporting test case. Gradually I can start using this for more complex pet projects, something which I can enjoy writing in my leisure time, or just to get myself at par with whats latest.

Idea Sample project

That was quick and easy. Although a more thorough example will demonstrate how effective Idea really is. For now the current setup brings a working IDE and functonal java installation to my machine.

At this stage, though Idea supports maven, it cant execute maven goals like clean, test, install since Apache Maven isnt installed on the machine yet. Installing maven involves just a couple of steps and I should be able to get going in no time.

1) Download maven from official site and extract zip contents to a folder.
2) Add the /bin to PATH by editing the ~/.profile file and appending the current maven location to the PATH variable like so PATH="$PATH:~/Dev/apache-maven-3.2.3/bin"
3) Verify maven is working like so mvn clean
4) It might complain that it cant find the pom.xml in current location, but thats besides the point. We just had to check if mvn is available on PATH

Coming back to Idea project, I should be able to execute maven goals from within the IDE as well. But there’s a catch. Idea understands maven installation from the M2_HOME env variable which I havent yet set. I can edit the ~/.profile to supply these values and check with Idea again.

export M2_HOME="/home/koolksp/Dev/apache-maven-3.2.3"
PATH="$PATH:$M2_HOME/bin"

Yep that worked. For some reason, Idea does not understand path like ~/Dev/apache… so had to give complete path instead.

Tried maven clean test and install goals from within Idea gui and worked as expected. Equivalent cli commands would be

mvn clean
mmn test
mvn install

Thats all. The setup is now ready and raring to go.

Programming on Linux

Over the years I have been making myself familiar with and increasing proficiency with range of open source and cross platform technologies. After all being in the software industry, you have to keep yourself upgraded with the several tools and technologies of the trade. I reckon most people have their workstation setup on Windows and likewise are less familiar with setting up the same technology stack on a linux machine. On a fresh Elementary OS setup, not much is available for the user to start being productive in terms of software development. A quick check for list of installed software on Elementary OS put things into perspective for me.


koolksp@koolksp-3000-N100:~$ which java
koolksp@koolksp-3000-N100:~$ which groovy
koolksp@koolksp-3000-N100:~$ which ruby
koolksp@koolksp-3000-N100:~$ which ant
koolksp@koolksp-3000-N100:~$ which mvn
koolksp@koolksp-3000-N100:~$ which gradle
koolksp@koolksp-3000-N100:~$ which g++
koolksp@koolksp-3000-N100:~$ which gcc
/usr/bin/gcc
koolksp@koolksp-3000-N100:~$ which python
/usr/bin/python
koolksp@koolksp-3000-N100:~$

So of the list of programming languages I know or would like to know better, hardly any came installed with the OS, with the exception of the gcc compiler and the python interpreter.

It got me thinking, what if I start making a list of things that I need to install or configure to start developing some pet projects on my home laptop. I think that is the inspiration for this section of the blog, where I plan to touch up on the technology basics, document the setup and config details and get started with some demo development.

Other blogs that will follow in this section will be aimed at making the basic elementary setup into a lean mean dev machine. Let me list things that I can bring up in blogs to follow

1) Java development, IDE setup
2) Build tools – Maven, Gradle
3) Messaging technologies – ActiveMQ, RabbitMq
4) Scripting languages – Ruby, Python, Groovy

What I will document here, would serve as quick reference/quick recap for me on later dates and probably help reader to get started with Programming on Linux sooner than they thought.

So … Keep Calm and Code on!