Solution Architecture

I have made a formal commitment towards developing myself as a Solution Architect. This blog post will have the links to everything which i have found useful.

http://scn.sap.com/community/career-center/blog/2014/05/25/from-developer-to-solution-architect-essential-skills-for-climbing-the-it-professional-ladder

http://scn.sap.com/community/technology-innovation/blog/2013/01/03/so-you-want-to-be-an-architect-let-s-talk-about-street-credibility

Ramblings 2 @ Java

This post is a continuation of ramblings of the past.

Javascript frameworks:

Step back jQuery, it is now Backbone.js , Ember.js and Angular.js. It has to be seen who is winning, though. I have not used any of these in my project but each one of it, looks an interesting prospect. Check out this link to understand the differences. Underscore.js is a powerful complement to Backbone.js/jQuery.

Updated: React is a new javascript framework which looks simpler in implementation and is going to give serious competition Angular.

Security frameworks:

Spring security, Apache Shiro and JBoss PicketBox are in contention here. Spring security has the first mover advantage. But, Apache Shiro is easier to learn and implement. JBoss PicketBox is good for JBoss fans.

Single Sign-on:

It is always good to understand what each framework offers before embarking on a solution implementation. OAuth2 seems to be a preferable option if you are starting now and don’t have a SAML infrastructure already.  For enterprise, SAML still seems to be holding the ground. Learn more here and here too.

Shibboleth provides an open-source SAML implementation of SSO capability.

Source-control, Continuous Integration and Automated Deployment:

There seems to be a new stack for this GitHub + Jenkins + Puppet. A quick reality check of the competitors in each of the spheres is listed below.

GitHub/GitLab/Gitorious: For source control management, GitHub is leading the pack.For a quick differentiation, Check here.

Hudson/Jenkins : Continuous integration server which integrates with a git repository. Jenkins has taken over Hudson, Check here.

Chef/Puppet : Automated application deployment on servers. Puppet seems to be ahead of the race marginally, Check here.

Read this for a typical implementation.

Handy Linux Commands

Usage Command
Check for the Version of Linux uname -mrs  or
Open file using cat /proc/version or
uname -a [All information]
Check for the Machine architecture uname -mrs
i386 and i686 = 32-bit; x86_64 = 64-bit
Check for the Server release details lsb_release -a
Check the processes running ps fuxxx , ps auxxx
Checking whether a port is open or not telnet <ip_address> <port_no>
Updating access rights to execute a program chmod +x ./<program_name>
Searching for specific text occurrences grep <search_term> *
Checking top 100 lines of a file tail -100f <file_name>
Running a program in back-ground nohup ./<program_name> &
Checking ip address /sbin/ifconfig or ip addr show
Checking which process is cosuming how much top
Checking how much space is available in current drive df -h
Killing a process kill -9
Copying file/directory from a linux server [File]scp <USER_NAME>@<HOST_NAME>:<USR_DIRECTORY>/sample.txt .
[Directory]scp -r <USER_NAME>@<HOST_NAME>:<USR_DIRECTORY>/ .
Clear the screen clear screen
Java Set-up in linux Click here

Jar with dependencies using maven

In the earlier post, though we had dependencies for our jar, we just used them while compiling them. Hence, when we execute our jar, it is required that, they be included in the class-path while executing our jar.

Though, this sounds reasonable enough, there are situations when it becomes tedious to include the dependencies in the class-path every-time you want to run the jar,especially, when there are more than a few dependencies and multiple main-classes. A simpler way is to bundle the other dependent jars in our jar.

Hmmm. This may sound a little off the mark. It is true you cannot bundle the dependent jars in your jar. Albeit, you can include the classes of your dependent jars in your jar. This will solve the problem. Whoa!!! how do i do it?

This can be done pretty easily using Maven in tandem with an assembly.xml. Following are the key points:

a. Use Maven Assembly plugin to assemble the class files in a jar and include their dependencies as well
b. Maven Assembly plugin requires an additional assembly.xml which in turn specifies format e.g. jar and depndency-set
c. Configure the assembly.xml as part of same project and use it from pom.xml using maven assembly plugin
d. Generate one single jar with all dependencies

The sample pom.xml looks like below:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.schoudari.blog</groupId>
  <artifactId>my-blog-reader</artifactId>
  <packaging>jar</packaging>
  <version>1.0.0-SNAPSHOT</version>
  <name>My Blog Reader</name>
  <properties>
    <log4j.version>1.2.16</log4j.version>
  </properties>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId><!--1.Use Maven assembly plugin to assemble the jar-->
        <configuration>
          <attach>false</attach>
          <descriptors>
            <descriptor>src/assemble/assembly.xml</descriptor><!--2.Assembly configuration-->
          </descriptors>
          <archive>
            <manifest>
              <mainClass>com.schoudar.blog.MyBlogReader</mainClass>
            </manifest>
          </archive>
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>${log4j.version}</version>
    </dependency>    
  </dependencies>

</project>

The sample assembly.xml is specified below:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
  <id>jar-with-dependencies</id>
  <formats>
    <format>jar</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <dependencySets>
    <dependencySet>
      <outputDirectory>/</outputDirectory>
      <useProjectArtifact>true</useProjectArtifact>
      <unpack>true</unpack>
      <scope>runtime</scope>
    </dependencySet>
  </dependencySets>
</assembly>

Useful Links:
http://www.ibm.com/developerworks/java/library/j-5things13/index.html

Creating a Jar using Maven

In the earlier post, we had seen how to create a jar, in this post we will see how to create a jar using maven. Following are key points in creating the jar using maven.

1. Specify the packaging type e.g. jar.

2. Compile the source code. Use  maven-compiler-plugin here.

3. Generate eclipse related files like .classpath, etc. Use maven-eclipse-plugin. [optional]

4. Bundle the java class files in a jar. Use maven-jar-plugin.

5. Provide the main-class[entry point] for your jar in the mainfest.

6. Execute the unit-tests of your jar before creating the jar. [optional]

Refer to the sample pom.xml below:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.schoudari.blog</groupId>
  <artifactId>my-blog-reader</artifactId>
  <packaging>jar</packaging> <!--1.Packaging Type -->
  <version>1.0.0-SNAPSHOT</version>
  <name>Blog Reader</name>

  <properties>   
    <log4j.version>1.2.16</log4j.version>
  </properties>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId> <!--2.Compiles the source-code -->
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-eclipse-plugin</artifactId> <!--3.Generates the eclipse-related files -->
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId><!--4.Creates a jar -->
        <configuration>
          <archive>
            <manifest>
              <addClasspath>true</addClasspath>
              <mainClass>com.schoudari.blog.BlogReader</mainClass><!--5.Add main class -->
            </manifest>
          </archive>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId><!--6.Executes the unit-test cases -->
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>${log4j.version}</version>
    </dependency>       
  </dependencies>  
</project>

Basics of Jar

A few years back, i was asked why a class in jar was not running as expected from command prompt. The answer was quite simple, the dependencies of the class are not available.

There is a common misconception that you create a jar and everything runs out of the box for you when you run the main class. Now what is the main class in the jar. Let me give you some introduction to jars:

a. Jar – Java archive. As the name says, it archives a set of java files.

b. Common Jar Operations

Operation Command
To create a JAR file jar cf jar-file input-file(s)
To view the contents of a JAR file jar tf jar-file
To extract the contents of a JAR file jar xf jar-file
To extract specific files from a JAR file jar xf jar-file archived-file(s)
To run an application packaged as a JAR file (requires the Main-class manifest header) java -jar app.jar

c. In general, a java file uses some or the other open source libraries e.g. log4j.jar, etc. Hence, when we create a jar, it is required that it is available in the class-path when we are creating the jar, so the class files can be created and then, they can be bundled. The same principles applies when you execute the jar file as well.

d. Every jar should have at-least one Main-class. Main-class is a class, which is a public class, with the public static void main(String[] args) method. This is the entry-point for all the classes in your jar. P.S. There can be more than one main class as well. In such a case, it is preferable not to have a main-class specified in the manifest.

e. A jar generally comes with a MAINFEST file. This is like meta-information about a jar. e.g.

Manifest-Version: 1.0
Main-Class: MyClass
Class-Path: MyUtils.jar
Created-By: 1.6.0 (Sun Microsystems Inc.)

Useful links:
http://docs.oracle.com/javase/tutorial/deployment/jar/index.html