Friday, December 20, 2013

Spring MVC 3 + Spring Security + Hibernate 4 tutorial

This tutorial helps you to create a spring mvc application integrated with hibernate 4 and Spring security. Before continuing read through my previous article on Spring MVC 3 - Hello world example

The tutorial uses MySQL as database and source code enhanced from the previous Hello world example.

Changes to your pom
Add/modify the following to the properties section of your pom.xml. The spring version is increased to 3.2.3 to support transactions.
Add the following to the dependencies section

Now we are set to use hibernate and spring security in your application.

Create file application-security.xml inside your webapp >> WEB-INF >> spring folder and paste this content.
Replace the following to your servlet-context.xml. The changes include adding necessary namespaces and made beans as default namespace for convenience.
Create a new file controllers.xml Now all the configurations are done.  Create your controllers and views, I have not explained the views, web.xml for simplicity. The complete sample can be found here in github
Create User.java with the following content, make sure your test database has an user table with fields that matches the properties in the below
Create UserController.java with the following content
Create UserDAO.java with the following content
Download the complete code in github

Friday, November 15, 2013

Spring MVC 3 - hello world example - Quick start

This tutorial helps you to quickly create and run a spring-mvc hello world application.  Spring version used for this example is 3.2.3-RELEASE.

Prerequisites
  1. JDK 1.6+
  2. Eclipse Juno+
  3. Spring IDE 3.4+ for eclipse
  4. Maven 3
  5. Maven Integration plugin for eclipse
  6. Tomcat 7+
Initial Steps
Right click and create New --> Spring project.  In the next dialog, fill in the project name as "spring-mvc-spring-sample" and select "Spring MVC Project".  Please specify package name "com.ananth.spring" and click Finish.


Run your application
Right click on your eclipse project --> Run As --> Run on server --> Finish.
From your browser navigate to http://localhost:8080/spring/ you will see this screen.

The source can be download from github. Next chapter Spring MVC with Spring security & Hibernate.

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed - Axis2

I was recently working on writing some client code which makes multiple webservices calls.  The stubs for both my client were generated using Axis2.  I had to make requests to 2 different services, where one of the service was serving a dummy SSL certificate and the other one was serving a valid SSL certificate.

I landed up getting the following exception,
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:154)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)

Here are the steps I took to overcome this error,

Bypass SSL security check
I googled and got several links on how to bypass the SSL security check in Java.  Most of them were suggesting to use XTrustProvider.install() to turn off SSL check.  After implementing this solution the error went away if I invoked only the service which was serving a dummy SSL certificate. When I tried  using both the services I again got caught with the same exception,  though I tried ignoring the SSL check in the 2nd service.  Axis2 actually for some reason "reuses" or caches the security certificate and the SSL socket factory is singleton. So use this class only if you are using a single service.

XTrustProvider.java
Loading the certificate to the "trust store"
Use the following InstallCert.java to generate your certificate and tell your SSL socket factory to use this trust store like this.  Note:  Add this line before the call to your first service,  else you will end up in the same exception.
InstallCert.java

Thursday, October 10, 2013

How to make Eclipse autocomplete to suggest as you type

Recently some one was asking if Eclipse content assist/autocomplete can be made to suggest as I type my class name? Immediately I could remember XCode for mac doing something like that and I felt there should be a way in Eclipse.

By default eclipse autosuggest would trigger once you type "." the goal is to make it suggest me the "Type/Class" names too. How to make it do?

Steps:
Go to Eclipse(Windows for windows users) --> Preferences --> Java --> Editor --> Content Assist

Under subsection "Auto Activation" the default value for Auto activation triggers for Java will be "." change this to

.ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

Optionally you can increase/reduce the Auto activation delay to a lesser value.



You are all set! Now Eclipse will start suggesting as you type.

Thursday, August 1, 2013

How to open multiple eclipse instances on Mac

Multiple instances of eclipse in mac can not be opened by default. While windows users have the privilege to run several eclipses at the same time. I was wondering if there is a way to the same in Mac.

Though there are other solutions like editing the eclipse.app etc, the best solution is to use "OSX Eclipse Launcher utility plugin".

Follow these simple instructions
  1. Go to help --> Eclipse Marketplace...
  2. Search for "OS X Eclipse laucher utility"
  3. Cick Install, Next, Finish and restart your eclipse.
Once the plugin is installed, click on File --> Open Workspace.  Here you go, a new instance of eclipse is opened with a new workspace.


Monday, July 29, 2013

How to right click on a mac mouse

Initially I was puzzled on how do I right click on my new mac mouse. :-) If you have searched for this article, you also would have had the same question.

Navigate to System Preferences --> Mouse --> "Check" Seconday click --> Click on right side.

Once you are done with that you can right click on the mac mouse.

Thursday, July 25, 2013

How to convert XML to Java object and vice versa in runtime?

Well the obvious choice would be to use JaxB, due to its familiarity. Let us see it with a simple example. JAXB is governed by the same team as Glassfish. JAXB comes by default with JDK1.6+. JAXB stands for Java Architecture for XML Binding.

XML has become a common form of data storage in many applications and for webservices. There are two common operations that are required while dealing with XML from Java. Read an xml file and convert it to a Java object, and write a Java object to an xml file.

JAXB does both the above said operations and those operations are called as
  1. Marshalling – Convert a Java object into a XML.
  2. Unmarshalling – Convert a XML into a Java Object.
Let us see this with an example,
Marshalling: Converting Java object to XML
Its a simple process, lets see this with a sample program
Output
While running the above example you will run into the following exception,

Exception in thread "main" javax.xml.bind.MarshalException
 - with linked exception:
[com.sun.istack.internal.SAXException2: unable to marshal type "com.ananth.samples.Employee" as an element because it is missing an @XmlRootElement annotation]
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:317)
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:243)
at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:75)
at com.ananth.samples.Java2XMLExample.main(Java2XMLExample.java:20)
Caused by: com.sun.istack.internal.SAXException2: unable to marshal type "com.ananth.samples.Employee" as an element because it is missing an @XmlRootElement annotation
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:216)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:286)
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:462)
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:314)
... 3 more

To fix the above exception you have to add an @XmlRootElement annotation to your Employee Pojo.
Instead of System.out you can point to the File to which you want to write the output during jaxbMarshaller.marshal(employee, file);. Once make the change while rerunning the sample will give your the following output.
UnMarshalling: Converting XML to Java object
Its a simple process, lets see this with a sample program
Now, I had a question why do I should I have a @XmlRootElement annotation in my pojo.  Cant I do I deal with my existing POJOs of my application?
The answer is you cant do it with JAXB but there are other options like XStream. I have referred their two minutes tutorial and it really look me only 2 minutes to try it out.
Add the XStream maven dependency and after that it is as easy as calling toXML and fromXML methods of XStream object.


Friday, July 19, 2013

XML reader error: javax.xml.stream.XMLStreamException: ParseError at [row,col]

100/100 times I know that this exception happens while there is a parse error in your xml and there is something wrong at the specified row and column.

Knowing the following exception is due to an XML parse error, recently I was puzzled for a while trying to look into the actual content of the file.  I couldn't see any closing tag error at the row and column mentioned.

After looking closer, I figured out my xml is used by multiple threads where a few threads were trying to write the XML and the other was trying to read the same file. And the exception was due to thread safety and the file was not fully written before the read. :-)

Message: XML document structures must start and end within the same entity.
com.sun.xml.internal.ws.streaming.XMLStreamReaderException: XML reader error: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[8829,4]
Message: XML document structures must start and end within the same entity.
at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.wrapException(XMLStreamReaderUtil.java:256)
at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.skipTags(XMLStreamReaderUtil.java:146)
at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.skipElement(XMLStreamReaderUtil.java:119)
at com.sun.xml.internal.ws.wsdl.parser.WSDLParserExtensionFacade.definitionsElements(WSDLParserExtensionFacade.java:129)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parseWSDL(RuntimeWSDLParser.java:314)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:135)
at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:254)
at com.sun.xml.internal.ws.client.WSServiceDelegate.(WSServiceDelegate.java:217)
at com.sun.xml.internal.ws.client.WSServiceDelegate.(WSServiceDelegate.java:165)
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:93)

Monday, June 17, 2013

java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

I got this exception while I was trying to execute an open source application that I found from the web. I was trying to run the application from my eclipse managed tomcat 7 server. I noticed that my project's maven dependencies were not having the right jars.
This problem can be fixed by adding maven dependencies in the project's web deployment assembly.
  1. Open the project's properties (e.g., right-click on the project's name in the project explorer and select "Properties")
  2. Select "Deployment Assembly"
  3. Click the "Add..." button on the right margin
  4. Select "Java Build Path Entries" from the menu of Directive Type and click "Next"
  5. Select "Maven Dependencies" from the Java Build Path Entries menu and click "Finish".
You should see "Maven Dependencies" added to the Web Deployment Assembly definition after the following the above steps.

Friday, June 14, 2013

Wikipedia, RHEL ditches MySQL and moves to MariaDB

Prior to this Wikipedia has moved to MariaDB from MySQL recently.

According to news from the Red Hat summit which concludes in Boston on Friday, RHEL 7 will also include MongoDB.

The switch was expected to happen after Red Hat's community distribution Fedora announced earlier this year that it would be moving to MariaDB. But it will come as a major jolt to Oracle, the owner of MySQL. (openSUSE, the community distribution of SUSE, announced a switch to MariaDB at the same time as Fedora.)

Many changes in Fedora foreshadow changes in the enterprise distribution.

Once RHEL makes the switch, it will flow on to CentOS, a distribution that provides RHEL without the trademarks, hence making it free in terms of cost. CentOS is widely used by small businesses.

MySQL became Oracle's property after the company bought Sun Microsystems in 2010. There have been many complaints about its stewardship of what was once the last word in open-source database software.
MariaDB is a fork of MySQL that was begun by Ulf Michael Widenius under his new company, Monty Program. Widenius is one of the three co-founders of the original MySQL. The company was sold to Sun in 2008.

Earlier this year, Monty Program merged with SkySQL, a company set up in October 2010 by former employees of the original MySQL. Notable among SkySQL's ranks are former MySQL senior vice-president of global services, Ulf Sandberg, and adviser David Axmark, another of the three co-founders of MySQL.

Widenius and several others raised objections to Oracle's acquisition of MySQL but failed to stop the sale going through.

MySQL's first employee in Australia, Arjen Lentz, said Fedora and OpenSuSE were community driven, whereas RHEL's switch to MariaDB was a corporate decision with far-reaching implications.

"I presume there is not much love lost between Red Hat and Oracle (particularly since the "Oracle Linux" stuff started) but I'm pretty sure this move won't make Oracle any happier," said Lentz, who now runs his own consultancy, Open Query, from Queensland. "Thus it's a serious move in political terms."

He said that in practical terms, MariaDB should now get much more of a public footprint with people (people knowing about MariaDB and it being a/the replacement for MySQL), and direct acceptance both by individual users and corporates.

"Monty Program actually merged (aka was bought) by SkySQL a few months ago. SkySQL does not have significant activity in Australia and New Zealand, Open Query has. SkySQL is currently mainly active in Europe.

"So in terms of significance for AU/NZ, Open Query is definitely happy with this move, and is set to gain business for it. Which is nice in economic terms for Australia, it's not a foreign company with Australian clients."

Thursday, June 13, 2013

Type mismatch: cannot convert from null to double

Today while I was doing a code review with my team mates, I noticed some code like this
When I asked them why do you type cast "null to double", the answer they gave was I got "Type mismatch: cannot convert from null to double". There are 2 possible solutions for this,
  1. Use Double instead of double, then you may use null.
  2. Use "not a number" (NaN) like this 
submit to reddit

How to remove a plugin from eclipse

Go to Help > About Eclipse > Installation Details, select the software you no longer want and click Uninstall. (On Mac it is Eclipse > About Eclipse > Installation Details.) In older versions, you might need to Run Help > Software Updates > Manage Configuration..., select the feature of interest, and disable it with the task shown in the right window.

When a feature is disabled, all its plug-ins will be disabled also. They are still available on disk, and they can be enabled at any time in the future.

To physically remove the feature and its plug-ins, you will have to manually remove the feature from the eclipse/features directory and its plug-ins from the eclipse/plugins directory. I advise extreme caution here. Remove the wrong ones, and you may spend quite some trouble restoring your Eclipse to a stable state.

Thursday, June 6, 2013

How to use VIM editor

VIM Editor Commands
Vim is an editor to create or edit a text file. There are two modes in vim. One is the command mode and another is the insert mode.
  1. In the command mode, user can move around the file, delete text, etc.
  2. In the insert mode, user can insert text.
Changing mode from one to another
From command mode to insert mode type a/A/i/I/o/O (see details below)
From insert mode to command mode type Esc (escape key)

Some useful commands for VIM
Text Entry Commands (Used to start text entry)
  • a     Append text following current cursor position
  • A    Append text to the end of current line
  • i      Insert text before the current cursor position
  • I     Insert text at the beginning of the cursor line
  • o    Open up a new line following the current line and add text there
  • O   Open up a new line in front of the current line and add text there
The following commands are used only in the commands mode.
Cursor Movement Commands
  • h                   Moves the cursor one character to the left
  • l                    Moves the cursor one character to the right
  • k                   Moves the cursor up one line
  • j                    Moves the cursor down one line
  • nG or :n       Cursor goes to the specified (n) line (ex. 10G goes to line 10)
  • ^F (CTRl F) Forward screenful
  • ^B                Backward screenful
  • ^f                 One page forward
  • ^b                One page backward
  • ^U               Up half screenful
  • ^D               Down half screenful
  • $                  Move cursor to the end of current line
  • 0 (zero)        Move cursor to the beginning of current line
  • w                 Forward one word
  • b                  Backward one word
Exit Commands
  • :wq  Write file to disk and quit the editor
  • :q!   Quit (no warning)
  • :q     Quit (a warning is printed if a modified file has not been saved)
  • ZZ   Save workspace and quit the editor (same as :wq)
Text Deletion Commands
  • x       Delete character
  • dw    Delete word from cursor on
  • db     Delete word backward
  • dd     Delete line
  • d$     Delete to end of line
  • d^     (d caret, not CTRL d) Delete to beginning of line
  • Yank (has most of the options of delete)-- VI's copy commmand
  • yy      yank current line
  • y$      yank to end of current line from cursor
  • yw     yank from cursor to end of current word
  • 5yy    yank, for example, 5 lines
  • Paste (used after delete or yank to recover lines.)
  • p       paste below cursor
  • P       paste above cursor
  • "2p   paste from buffer 2 (there are 9)
  • u       Undo last change
  • U      Restore line
  • J       Join next line down to the end of the current line
File Manipulation Commands
  • :w    Write workspace to original file
  • :w    file Write workspace to named file
  • :e     file Start editing a new file
  • :r     file Read contents of a file to the workspace
  • To create a page break, while in the insert mode, press the CTRL key and l. ^L will appear in your text and will cause the printer to start A new page.
Other Useful Commands
Most commands can be repeated n times by typing a number, n, before the command. For example 10dd means delete 10 lines.
  • .      Repeat last command
  • cw   Change current word to a new word
  • r      Replace one character at the cursor position
  • R     Begin overstrike or replace mode – use ESC key to exit
  • :/      pattern Search forward for the pattern
  • :?     pattern Search backward for the pattern

Examples:
Opening a New File
  1. type vim filename (create a file named filename)
  2. type i ( switch to insert mode)
  3. enter text (enter your Ada program)
  4. hit Esc key (switch back to command mode)
  5. type :wq (write file and exit vim)
Editing the Existing File
  1. type vim filename (edit the existing file named filename)
  2. move around the file using h/j/k/l key or any appropriate command
  3. edit required text (replace or delete or insert)
  4. hit Esc key (exit from insert mode if you insert or replace text)
  5. type :wq

Wednesday, June 5, 2013

How to exit from an unix manual page

Though the answer is simple, I have struggled a bit to get out of the man page. Thought this could help for unix beginners like me.

"man" command is very useful to read the manual of any commands that you use from terminal on a linux/mac machines.

From your terminal "man command-name" takes you to the manual page.

In order to navigate in the pan page use "up" or "down" arrow keys for navigation. In certain cases you may have to use enter key.

To get out of the man page simply type "q", this will take you to the command prompt from open terminal.

Ex: man ssh, man chmod, man ls

How to create a new git local branch and push to repository (remote/origin)

From your terminal using commands
Check your git version with the following command,
git --version
if you have git version equal or greater than 1.7.0, you should be able to do with the following commands.
git checkout -b newbranch

git push -u origin newbranch
The first command creates a new branch from your current local branch. In order find what's your current branch use the command "git branch -a". It will list all available branches, the current branch will be preceded with a *.
The "-u" option is available only from git 1.7.0. It refers to "upstream" to where you want to push to or pull from.

From eclipse
Right click on your eclipse project Team -> Switch to -> New branch.

Create branch from eclipse

Give your new branch name in the following dialog and then click Finish. This will create a new branch from your current working branch.

Make all your changes to the new branch, to push the newly created branch right click Team -> Commit & Push (EGit2.x versions).

From github
The simplest way to create a new branch is from Github. If you have push access to the repository, start typing the new branch name in the search box of switch branches/tags. This box will appear once you click on the down arrow near branch. Once you complete typing the branch name, you will see an option to create new branch with the name provided. Click on it, you are done.

Create branch from github

submit to reddit

Thursday, May 30, 2013

Why should you have your code "neat"

It is a painful truth that most of my fellow developers don't care about code readability and maintainability.  Sometimes its frustrating to make changes on an unformatted, in other words poorly written code.

Code that we write represents our brain and I consider my code as how an artist considers his painting.

After reading an article on Style matters, I thought of writing this post on few important readability factors and how important it is to have your source code neat.

Top 5 readability & maintainability factors
  1. Documentation with proper comments
  2. Formatted code with proper indentations
  3. Organized file folders
  4. Proper naming conventions
  5. Never use deprecated code
Comments & Documentation
A good developer learns a project just from the code; javadoc plays a significant role in the learning process. Imagine that all open source projects and JDK code with no comments and documentation.  I am sure that it would at least take 10 times more effort to figure how to use them. A good javadoc in your application saves enormous amount of time for fellow developers.
All IDEs shows help texts for a method or class on mouse over for quick assistance, remember they all come from the javadoc of that method or class.  When you leave your code with no comments, then you are letting some fellow developer to be handicapped in some way.

Formatted code with proper indentations
When my sister write Java classes in notepad for her college project,  it is acceptable to have a code which doesn't have a decent formatting. Considering the modern IDEs that we use, formatting takes a few seconds. It has to be a habit to write formatted code and not for the sake of your manager or your lead wants it.
To the least there are options to do a format at your project level which formats all your classes in the project.  For example using eclipse, "Right click on your project -> Source -> Format". Boom all your code is formatted decently with the basic code formatting settings, however you can go and edit the settings as you want and also you can share it across your team as an xml file.

Organized file folders
During several code reviews that I have witnessed project documents kept under "src". One common answer I heard from developers was its easy to access. I was shocked to see project documents going inside your deployable files. A good java project should have well organized packages which very well represents OO design being followed. Writing everything in the same folder makes it unmaintainable as the project grows.

Proper naming conventions
In most cases the people who maintain the code is not same as the author. They may not be knowing the project as good as the original author, or may be less skilled programmers compared to the author. Having very good class, method and variable names makes it very much easy for the person who maintains it. Reading java code should more or less be similar to reading english. Following descriptive naming convention helps to understand the code much faster. Using i, j, k, abc, xyz as your method or variable names through out your project makes it almost an unsolvable puzzle for people who follow. Sometimes it makes it tougher to debug for even the author who wrote it.

Never use deprecated code
A method or class is deprecated when a code is "buggy" or "inefficient" or for a "bad coding practice". And it is represented with @deprecated annotation. A good API would always give an alternative better option before deprecating the existing one. Look for the alternative option and never use deprecated code.

Note:  All the points discussed here are for code written Java and may be applicable for other programming languages too.

Wednesday, May 22, 2013

Collection of very interesting unix commands

How to get your top 100 unix commands

history | sed "s/^[0-9 ]*//" | sed "s/ *| */\n/g" | awk '{print $1}' | sort | uniq -c | sort -rn | head -n 100 > commands.txt

How to copy a file to all subfolders of a directory using unix command

find . -type d -exec cp pathtofile {}/ \;

How to delete all .svn folders from current directory using unix command

find . -type d -name '.svn' -print -exec rm -rf {} \;

How to list all network connections (including which app they belong to)

lsof -i -nP

How to run the last command as root

sudo !!

How to execute the previous command until it is successful

until !!; do :; done

How to display summary of git commit ids and messages for a given branch

git log --pretty='format:%Cgreen%H %Cred%ai %Creset- %s'

How to list all file extensions present in the current directory

ls | perl -lne '++$x{lc $1} if /[.](.+)$/ }{ print for keys %x'

How to get your top 10 commands with number of times you have used it

cat .bash_history | cut -f 1 -d\ | sort | uniq -c | sort -r | head

To generate list of usernames from an svn logs (Run from top level of the svn project)

svn log | grep -E "r[0-9]+ \| .+ \|" | awk -F"|" '{print $2}' | sort | uniq > ~/authors.txt

How to get process details from its pid

ps -p $pid

How to open firefox profile manager

/Applications/Firefox.app/Contents/MacOS/firefox-bin -p

Credits:
https://docs.google.com/forms/d/1XNMoSdfYFe_WkPfU--M88oL00PDLIOAo1HxjhZvZYJ4/viewform
Mr. Robg
My previous post
http://stackoverflow.com/questions/1102986/most-powerful-examples-of-unix-commands-or-scripts-every-programmer-should-know
http://www.commandlinefu.com/commands/browse/sort-by-votes

Monday, May 20, 2013

Few must know unix commands

After spending more than 9 years of my life in microsoft os,  I feel great now to use my Mac notebook.  Especially I have fallen in love with the terminal and thrilled to learn the power of unix.  I curse myself for not being an unix user so far. Well, its never late to start. :-)

As a beginner I thought of sharing my learnings to my fellow unix beginners with few basic commands that you "must" know as an unix user.

Few basic "must" know unix commands

1. ls - list files and folders

What is ls?  A command to list all files and folders in a directory.
Usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...]

Explaining few commonly used parameters of lsls command args

2. pwd - present working directory

What is pwd?  A command to display the present working directory path.
Usage: pwd

3. chmod - file permissions changer

What is chmod?  A command to display the present working directory path.
Usage:  chmod arguments file
Permissions to a file can be of the following three categories,
  1. Read
  2. Write
  3. Execute
Let me try explaining this using numeric permissions,

Read

400 - read permission to owner
040 - read permission to group
004 - read permission to anybody

Write

200 - write permission to owner
020 - write permission to group
002 - write permission to anybody

Execute

100 - execute permission to owner
010 - execute permission to group
001 - execute permission to anybody

All permissions are in 3 digits,
xyz - indicates owner
xyz - indicates group
xyz - indicates anybody

For example:
chmod 777 filenmae means read-write-execute (full) permissions for anybody to the file.
chmod 644 filename means read and write permission to owner and read access to rest of the users to the file specified.
chmod 755 filename means read-write-execute permissions to owner and read and write access to others for the specified file.

The best way to learn any unix command is to do a "man" of that command.  For ex: man ls

Thursday, May 16, 2013

Git for beginners

Getting started with Git

I would advise to read through what is Git, and have a decent understanding of SCM process.
The first question everyone would get is why I should move away from my current SCM systems(CVS or SVN).  Well there are lot of articles around this topic if you google,  just a couple of quick reasons I would give to go with Git,
  1. Works the best if you are working decentralized.
  2. Stop questioning and just "Go with the flow" :-), git is grabbing more focus recently especially after GitHub's strong support.

Lazy comparison of Git vs SVN commands

I thought a simplest way is to compare Git vs SVN was through the basic commands used for day-to-day development.  Though we use the UI tools for regular activities, I am listing down the comparison by commands (lazy).

Git vs SVN commands
Git vs SVN commands
Two notable operations are the checkout and commit.  For any Git operations "clone" is a prerequisite, so to do a checkout initially you must clone the repository. If you notice a commit is not an actual commit to the repository instead it is to your local.  You need to do an explicit push to the repo after a successful commit. Remember everything happens in your local and not in your repo.

Tuesday, May 7, 2013

What is maven batch mode

Maven batch mode

Batch mode is to run Maven in a non-interactive, continuous integration environment. When running in non-interactive mode, Maven will never stop to accept input from the user. Instead, it will use default values when it requires input.

How to run maven in batch mode

Pass one of the params below to mvn command from your terminal,

--batch-mode, B

Monday, May 6, 2013

How to rename a file or folder in mac

Rename a file or folder in mac

If you were a windows user and new to mac, you would wonder how to rename a file in mac.  

The first thing you would try to do is a function f2, which wouldn't have helped.  The next effort you would have taken would be to do a cntrl click to look through the options.  That wouldn't have helped either.  May be you would have then tried "duplicate" or "alias" option and vent in vein.

Select the file or folder you want to rename and press enter key,  here you go now your will be able to  rename.

Friday, May 3, 2013

Struts 1 reaches End of life

EOL for Struts 1

It has been a great framework since the first release in 2000.  I have used it in many of my projects, but its available no more for enhancements.  :-)

As per Apache there will not be any security fixes as well in the future.  Apache's Announcement has the complete details if you are interested to know further.

Wednesday, May 1, 2013

How to delete all svn folders using mac terminal

How to delete .svn folders

On the process of importing my svn repository to my git (without history),  I wanted to delete all .svn folders from my project without deleting the rest of the content.  Here are the steps to do that,

cd /the root folder of your project
find . -type d -name '.svn' -print -exec rm -rf {} \;
  1. cd --> change directory to the root folder of your project.
  2. find . --> find in the current directory
  3. -type d --> file type directory
  4. -name '.svn' --> file name .svn
  5. -print --> print what matched up to this point (the .svn dirs)
  6. -exec rm -rf --> exec the command rm -rf (thing found from find)
  7. {} --> place holder for out from find
  8. /; --> / to escape ; and ' is to tell find that the command for exec is done

Tuesday, April 30, 2013

How to add a Git submodule from eclipse EGit

Adding a submodule using eclipse

You can add a new submodule to a repository by selecting a repository in the Git Repositories view and selecting the Add Submodule context menu option.

The wizard will prompt for the path and URL of the submodule being added. The path entered will be relative to the parent repository's working directory and the URL will be used to clone the repository locally.

Once the wizard is completed the submodule will be cloned, added to the index, and the submodule will be registered in the .gitmodules file as well as in the parent repository's .git/config file.

Credit: http://wiki.eclipse.org/EGit/User_Guide

Tuesday, April 23, 2013

Mac - How to fix disappearing scroll bar

Are you getting frustrated that you are not able to get your scroll bars in your macbook? You are not the only one. J

How to fix your scroll bar?

Here are the steps,
  1. Click on the Apple logo on the left corner.
  2. Click on System preferences
  3. Under personal select General
  4. Click on Always radio button under Show scroll bars. 
Now you can see your scroll bars not disappearing.