My favourite tips&tricks for the Best, Kick-Arse java IDE "IntelliJ IDEA".

Wednesday, June 22, 2005

Tip 6: Resin Session Expires on Build

Quick-Fix:
uncheck: settings->paths->J2EE build settings->Synchronize exploded directory

Understanding:
One of the fustrating experiences i had with IDEA for couple of days was that when ever i compiled code (even when everything was complied) my session expired in my application running on resin server.

Yes my project was configured as a web-application which gets automatically deployed when i compile. (i.e. output paths in IDEA pointed to "[RESIN_HOME]/webapps/[app-context]" folder).

This scene occurs when resin is configured to use the file system for session persistence(i cant go into the details of how it is done, maybe sometime later) and sessions are configured to persist somewhere within the application context folder. e.g.
"[RESIN_HOME]/webapps/[app-context]/WEB-INF/sessions".
So what happens is when ever we compile, IDEA tries to synchronise its project files with the deployement directory. Which basically means
1. It will copy everything configured in project to the deployement directory.
2. It will delete everything thats not configured in project but still present in deployment directory(e.g. persistent sessions stored inside deployment directory)

and so session expires, cause session files are deleted by IDEA. The behaviour exibhited by IDEA as mentioned in point (2) above can be controlled by a setting "settings->paths->J2EE build settings->Synchronize exploded directory" if we uncheck it the nothing is unnecessarily deleted from deployment directory during compilation.



Tuesday, February 01, 2005

Tip 5: Live Templates

One of the objective in my LIFE is "to achieve automation of all repeated tasks",
As I find it very disturbing to do (type) same stuff mechanically over and over again , so I always try to find ways that I could do use to automate stuff.

I found my self typing following lines over and over while coding any new "method" ,(foo in this case).

log.info("Entering method foo()");
log.info("Exiting method foo()");

and I stumbled upon "Live Templates"..................

So today's topic is Live templates:

Basically there are three types of live templates:
1 simple templates
2 parameterized templates
3 surround templates

Defining your own template can be very complex if one hasn't spent lots of time tweaking one.
Nevertheless this is very powerful feature of IDEA.

I wont be dwelling into the details of writing one.
Actually I will, we will be writing an extremely useful and easy to write live template, which is "1 simple template" (one listed above).

I also want to talk about "2 parameterized templates" too because they are very cool but it will have to wait until my next post.

So lets automate.

press 'ctrl+alt+s' then press 'm'

Enter following data in Dialog fields:

abbreviation: en
Group: user
Description: log entering method
Template text: log.info("Entering method $METHOD_NAME$");
context: Java Code

now click on edit variables:
here u'll see a variable named $METHOD_NAME$ because template text contains it. In the expression column select "methodName()", and also Check "Skip if defined" column.

voila , we are done.

now in any method type "en" followed by tab and enjoy the magic.

repeat the same trick for logging "exiting method".

there's lot more we can do with live templates, I hope I have encouraged u to look into the IDEA help for further tweaking live templates.

I'll be back with "2 parameterized templates" very soon.

till then,
chow.

Sunday, December 19, 2004

Tip 4: Fresh CVS Checkout from within IDEA

Most ppl are not aware of the fact that fresh CVS checkout can be done within IDEA. ppl resort to wincvs or turtoise for fresh CVS checkout. ok, without further ado i'll come to the point.

File > Checkout From CVS...

click on this menu item, and then select a repository in the next screen.

the best part is we can checkout any and all directories, including sub-directories of modules, we can slect multiple directories too.

File menu also contains "Browse CVS Repository" where u can actually see the contents of any repository.

so happy CVS Checkouting and Browsing.

(i know "Checkouting" sounds lame ;-)


Tuesday, December 14, 2004

Tip 3: CTRL+N with Camel Humps

ok, we normally use CTRL+N to open existing java files, suppose i want to open a file called,
------------------------------
InternalFooBarFile.java
------------------------------

so i'll type CTRL+N, small textbox will popup and i'll start typing

---------------------
inter
-------------------


and a file list starting with letters "inter" will be displayed, suppopse i have 25 files starting with word "Intern.." then i have two options
1. scroll down the list and select appropriate file.
2. or keep completing file name till the list narrows down and then select required file name from the drop down list.

or else there is a better way, called the CamelHump way.

after pressing CTRL+N , type "IFB.." in caps and see the magic, the list narrows down to the appropriate file.
note: "IFB" is in caps, so we have to type the capital letters in the file name, and the list narrows down.

i'll post some screenshots too.

chow.


Tip 2: ALT+F1

heres another one of my favorite keyboard shortcut:

We all know that we can open java files with ctrl+N (or non java with ctrl+shift+N) once the file is open , how do we find its source directory (quickly). How do we locate its in project windiow , package window, or in commander window (nobody uses commander window, I’ll talk about it in later tips.) there is a keyboard shortcut most ppl are unaware, so I share it here, the magic keystroke is

ALT+F1

In editor window when a file is open , just press alt+F1 and voila a menu pops up, select an menuitem and we jump to it, we can uses this key combo in many windows.
Its one of my favorite key-combos.

Until next tip, (quick,lightning fast tip)……………..
Keep Rocking.

Tip 1: comparing two code fragments (or two files) quickly.

Step 1 : select fragment 1 and copy it to clipboard.

Step 2 : select fragment 2 and right click it and select “compare with clipboard”. (Dont forget to select second code fragment, only then right-click on it.)
And voila…….. u can compare two code frags, with IDEA’s default diff plug-in.

U can use same technique to compare two files ;-)

More tips coming sooon. Keep looking………

Jigar.


=================================
Comments: by anon
=================================
You can also compare two local files with Idea's diffault diff plugin. Open project window by Alt+1. Select 2 files which u want to compare and then right click on mouse. select compare selected files option.
regards,
anon

=================================
my reply.
=================================

That’s right ,

But the issue sometime is , that two files are open in editor window, and we don’t know exactly where they are in the (directory structure) project window, (this can happen if we open the files using ctrl+N). And now if one file is in mailbox module and other is in obox/domains…. Then to locate these file in project window is a painful task , and the we have to scroll all the way, the control click two file……….. and u know the chore.

So this tip is for two files which are already open in editor and u want to quickly compare them (full file or code fragments). this method also uses IDEAs default diff plugin.

Jigar.