Showing posts with label eclipse. Show all posts
Showing posts with label eclipse. Show all posts

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.

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, 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.

Thursday, June 13, 2013

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.

Wednesday, June 5, 2013

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.

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, 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

Wednesday, April 21, 2010

Where does eclipse store recent workspace details

I knew that eclipse creates a .project file for every project that I create. I was trying to bundle my eclipse(I have lot of plugins) for my team. Who ever used it were getting the path of my default workspace which actually will not be available in their machine.

So where does eclipse store this default or recent workspace details?
You can find it under eclipse_home/configuration/.settings/org.eclipse.ui.ide.prefs file

How to get Spring Plugin for your Eclipse

Spring IDE

Spring IDE is an eclipse plug-in that helps in developing Spring Application. First we will see how to install the Spring IDE and later we will create our first Spring project using it. I am using Eclipse 3.4.1 version to demonstrate this.

To install Spring IDE, Go to Help -> Software Updates.


Click the "Add Site" button and enter "http://springide.org/updatesite" in the Add Site popup.


Select all the Spring IDE features and click Install.


Tuesday, September 1, 2009

P6Spy Open Source Framework to detect database performance bottlenecks in Java applications

What is P6Spy?
P6Spy is an open source framework for applications that intercept and optionally modify database statements. The P6Spy distribution includes the following modules:
  1. P6Log. P6Log intercepts and logs the database statements of any application that uses JDBC. This application is particularly useful for developers to monitor the SQL statements produced by EJB servers, enabling the developer to write code that achieves maximum efficiency on the server. P6Spy is designed to be installed in minutes and requires no code changes.
  2. P6Outage. P6Outage detects long-running statements that may be indicative of a database outage proble and will log any statement that surpasses the configurable time boundary during its execution. P6Outage was designed to minimize any logging performance penalty by logging only long running statements.
P6Spy includes installation instructions for JBoss, ATG, Orion, JOnAS, iPlanet, WebLogic, WebSphere, Resin and Tomcat.
What if you want it inside your favorite Eclipse IDE?
Don't worry there is an eclipse plugin for you here.

Monday, August 31, 2009

org.tigris.subversion.javahl.ClientException: Attempted to lock an already-locked dir svn

I had this error when I tried to update my source directory of my project. The reason for this exception is unsuccessful previous commit/update with svn. For example when you close your eclipse when a transaction takes place.

How do I resolve this issue?
  1. Right Click your project and select Team --> Cleanup
  2. Now try to do your update/commit
Try to do it at your project level since even if you try cleanup at source level and if the project has a lock, you will still not be able to do an update/commit.