Friday, December 18, 2009

Black friday madness

November, sweet november... month of the most important of holidays on Earth - the Black Friday! When all geeks can join in a mad rat race for the best deals, from clothing to electronic gadgets. For about 3 days people get in lines throughout the night, take enough red bull and 5 hour energetic drinks to glow green in the dark just to save some dough for the holidays. This kind of sacrifice may sound stupid for those who never experienced it, but since I came here to the US I can say this is the funniest holidays ever. Which other holiday can we find 47' HDTVs for less than half the regular price? Or get into a Walmart of Target store and see people fighting over cheap doorbuster deals? And hordes of geeks fighting online and killing web servers with DOS attacks trying to purchase half-price electronics? It is not for the faint of hearth, that is for sure!

This has been my approach during the past Black Fridays:
1. Monitor "official" BF sites for leaked ads weeks before the Black Friday - the ones I usually look into are:

http://bfads.net/
http://www.blackfriday.info/
http://www.black-friday.net/

2. Based on the leaked ads, make a list of your targets - when the time comes there is no room for you to decide what to buy, if you hesitate you lose the deal!

2. Create a webmail account just for deals and other junk - apply for email lists on every store you can think of. Stores sometimes send good deals in its email lists and this is sometimes the fast way to score it! Just make sure you create a "junk" email account to use only for that purpose or set rules in your existing email client (webmails like hotmail and gmail are good at that too) to move all emails from these companies to a separate folder. Some stores I get deals via email:

• Newegg - http://www.newegg.com/
• Amazon - http://www.amazon.com/
• BestBuy - http://www.bestbuy.com/
• Target - http://www.target.com/
• CostCo - http://www.costco.com/
• TigerDirect - http://www.tigerdirect.com/
• CompUSA - http://www.compusa.com/

And so much more... some stores also give you discount coupons when you signup, so make sure you do not overlook it.

3. Monitor deal sites and forums for the best deals - the ones I use the most are:

• DealDump - http://www.dealdump.com/
• SlickDeals HotDeals forum - http://slickdeals.net/forums/forumdisplay.php?f=9
• FatWallet - http://www.fatwallet.com/

* - make sure you also follow the BF forum at SlickDeals - you need all the information as fast as possible!

4. And lastly, refrain from sleeping. This is key - if you sleep during the Black Friday week you WILL lose good deals. If you sleep during Thanks Giving / Black Friday / Saturday you will lose the BEST deals! In times like these you can't rely on a cup of coffer, you need something "military grade" - in times like these 5 Hours Extra is your best friend! :D

5. Some brick-and-mortar deals are inviting - but think wisely before stepping into the streets. Many times the online stores match or even top the deal. Also, shopping online you can easily cover dozens of stores - while other people are in line for one single store!

I hope you already figured I made a few jokes so far, I am not that crazy to spend 8 hours in line during a freezing night like some people to score a TV or laptop for peanuts. But for those who still think I am a materialistic person, I guess that may be true... but I have to say that most of the Black Friday fun is actually in digging and "fighting" (by fighting I mean trying to get your order thru, not actually fighting a dude over a TV!) for deals than actually spending tons of cash on stuff. And if you are picky with what you buy you do not need to spend a lot on stuff, spend good time with friends - I have had lots of good times with the wife and a friend on Black Fridays - and get out of it with good stuff you can use.

I just wish I had the idea to write this post BEFORE this years' BF... oh well, perhaps no one will notice if I copy / paste it for next year's BF hehehe :D

Sunday, December 13, 2009

Setup Oracle's SGA size

I always work with Oracle databases on my laptop. I prefer to install them myself so I can tune it to run without using all my memory. Also, instead of installing Oracle directly on my laptop I always do so on virtual machines because this way it is easier to share my environments with my colleagues and to setup individual sandboxes for each project I am working on.

When I have to work with databases installed by others I found I usually have to decrease how much memory is assigned to Oracle. The scripts below describe how to do just that.

• update Oracle's SGA size:

-- show current SGA size
select sum(value)/1024/1024 from v$sga;

-- set SGA target size to 256MB
alter system set sga_target = 256M scope=both;

-- list buffer size
select current_size from v$buffer_pool;

-- list all pools
select pool, sum(bytes)/1024/1024 Mbytes from v$sgastat group by pool;

-- additional Oracle memory settings:
-- make sure you don't setup SGA to the same or higher size than MEMORY
alter system set memory_max_target = 512M scope=spfile;
alter system set memory_target = 512M scope=spfile;
alter system set sga_max_size = 256M scope=spfile;
alter system set sga_target = 256M scope=spfile;
-- you will need to restart Oracle for the changes to take effect (e.g. dbshut and dbstart)

Friday, December 11, 2009

UML diagram editors

From time to time people ask me to write UML diagrams. Sometimes it makes sense, but oftentimes I could be better off using my time on something else, like writing code, prototyping etc. Please don't get me wrong, I am not against good documentation or UML per se, but many people like to focus too much time on pretty documents with beautiful colorful diagrams while others, more pragmatic ones, prefer instead to have a system built on time, with quality and running in production. I like to think of myself as part of the "pragmatic" group.

I KNOW documentation is important, it can make the difference of people using your software or not, or your development team implementing what your client actually needs instead of something completely outlandish. That is not my point. My point for this post is that we should generally try to stick with what we are good on, but sometimes we just dont have a choice and have to work on something we KNOW isn't one of our strong skills. I thought PMs were supposed to limit such times, making sure tasks are assigned to the best resources based on their talents, but from my experience this is not exactly how it generally works. Not necessarily because of the PMs, sometimes they just don't have better resources to tackle the job.

But regardless what I think, as much I try to avoid wasting a lot of time writing documents that no one will read, sometimes I have no choice and just have to do it. I guess that is why they call it work, we can't like all that we do for a living. But what I can do is to try to finish it as quickly as possible, while still developing good quality documents. Which bring us to graphical design talent... and this is one area of talent that, I must confess, I am not especially gifted. I've worked with people born with natural talent for graphical design, they could use pretty much any tool and come up in few minutes with amazing diagrams or images or web site layouts etc. Think like someone opening Microsoft Paint and drawing a Mona Lisa in few minutes - yeah, I know, that was a stretch, but the point is, this is one of the things in life that you are either born with or you are not. Sure you can learn techniques to improve, but your true potential is more or less apparent from the early start.

Now the question is, how someone who's not a superfast gifted designer can create decent looking diagrams fast? My answer is "with especialized tools that format most things for you and you just have to enter the data". Think something a bit more especialized than Microsoft Visio. I can spend hours on Visio, moving lines and boxes, changing colors etc, and no matter what I do on it it will always end up looking like a pig. Before people say I did not try enough I can say that I tried learning from articles and books about it, but after some time I just accepted that I'm better of spending my time designing server-side frameworks, integrating enterprise applications, working with web services etc than creating striking-looking diagrams and working with web design. Which is actually quite liberating, to accept that I should leave such things for other people more gifted than myself while focusing on what, I like to think, am good on and like a lot to do. We should not try to do everything, but to focus on what we LIKE to do, right?

So what can I do when I need to write diagrams so they at least look decent and describe the concepts and ideas I am trying to document? And are finished quick so I can move on to other tasks? Well... tools that automatically generate the diagrams for me is a good start, I would think.

For example, NetBeans can automatically generate a UML class diagram from your source code. The generated diagram will be complex and unless you do some additional editing to filter out some of the noise no developer would ever waste time reading it, they would obviously prefer following the source code instead (assuming your source code is decently written - it is, right??), but it does look decent to see on a document or presentation. For those who dont know, it would appear that you put a lot of time on it... yeah, right! :P

Ok, so NetBeans is fine... but most times when I need to write UML diagrams I still do not have the classes yet, I am still discussing the solution design with a team. So I need something more flexible than that. But not too flexible that I would have to spend ages moving lines and boxes here and there! That is when I found a ridiculously small application called Quick Sequence Diagram Editor (QSDE).

Different than most similar tools, in QSDE instead of moving graphical elements around with your mouse you actually PROGRAM the sequence diagrams! I initially thought it was stupid and it would take much longer to write diagrams this way than just using the mouse... man I was wrong, and I am glad I kept trying to use this little gem. Now I can draw sequence diagrams real fast using QSDE.



Another decent UML tool that I used for other UML diagrams than sequence is StarUML. It is free and pretty decent for class diagrams, check it out.



This is just a simple (and lame) diagram made with StarUML

# References:

• StarUML - http://staruml.sourceforge.net/

• Quick Sequence Diagram Editor - http://sourceforge.net/projects/sdedit/

Saturday, November 21, 2009

Setting up a Maven repository proxy with Nexus

Background

Hey, quick hint: if you need quick get-to-the-point instructions on how to setup a free Maven repository proxy you can skip this section and scroll down to the next one. But, if you have some time to spare and are curious to know why one would need to setup his own Maven repository proxy, please bear with me a little and keep reading...

It should be a bit more than 3 years since I stopped using Ant in favor of Maven to automate builds, tests etc. After years using Ant for both personal and professional projects I got into a (then) new project where the dev team was using Maven. By that time I had already read about Maven and tried it briefly on minor prototypes just to evaluate it against Ant. In those first contacts it just seemed much more complicated than Ant, everything was considerably different etc.

Like I said, in this new project other analysts had already set it up the whole development environment, and since I had other pressing issues to focus on I did not learn much about it. The guys who set it up were amazing technical analysts, they picked excellent tools (they used AntHill Pro, among some others) and had a deep understanding of best practices for build management, test automation, quality control etc, and because of that I never had to trouble with nor had to deal with Maven or the build process myself.

Then, about another 1 and a half years ago, I began as the leading developer (and pretty much THE ONLY developer, designer, architect etc, I should add) on another project I wanted to stick with Maven. I guess I just got spoiled with things like automated dependencies download and the ability to integrate with such amazing apps like Hudson and Trac. Finally, the fact that AppFuse is heavily based on Maven also helped me made my mind.

A quick note on AppFuse: it is amazing how simple AppFuse makes it for us to kick-start our solutions rather than spend time on mundane things like defining your project hierarchy, setup Maven, Spring, Hibernate etc, but it comes with the price of being another level of abstraction – it help make things work even if you don't quite know how they work. Based on that, my advice is to use it or a similar super framework to save you time on redundant tasks but do take the time to learn how it does what it does!

So, long story short, that project I was working almost by myself grew, it got more developers and made its way to a production environment. During one of our code drops I got a message from the release manager that the build server was not able to build the application, something to do with a missing dependency. Well, yeah, if you ever worked with Maven you know one of the first things you learn is that it can download dependencies for you from the Internet. But this time it did not work. I built it locally, and it worked fine, no problem. I then removed my Maven repository, and that is when I got the exact same error we got in the build server – Maven was unable to contact one of the public Maven repositories the project depended on.

It is funny that I remember speaking to the build manager couple weeks before that incident that we should setup our project's own Maven repository to avoid something like that. But, as much as an outage of a Maven public repository is to be expected and therefore should be prevented, since I had never seen it before it got a very low priority in our To-Do list.

I found a quick fix for that by simply pointing the build server to my personal Maven repository, which had all required dependencies and did not need to download anything from the internet. So, in the end, there was no big harm other than me and the build manager having to spend about one hour to figure it out, upload files to build server and finally get the build completed.

What we can learn from this story? I don't know about you, but I learned that if we blindly depend on things beyond our control, as stable as they look like or use to be, they will fail us on unpredictable times.

It is my responsibility to shield my project from any outages on systems I do not control. The same way I always build simulators and stubs for external systems I must do something similar for external Maven repositories. And that is where a local project Maven repository fits in.

A Maven repository proxy is just a simple mechanism that acts as a mediator between your Maven-based applications and the Maven public repositories in the internet. It gives you control over your application dependencies – say, if you built your application yesterday with success, and assuming then that your Maven repository proxy is up to date, the public Maven repositories can burn and you will still be able to build your application. I hope they don't actually burn though, that was just an expression to make the point! Also, since you are not downloading hundreds of JAR files over the internet but from a local server, it may even improve your build times considerably.

So, which one to use? I tried 3 or 4 different Maven repository proxies and found Nexus to be the best one of the bunch, on my humble opinion. It could not be much simpler to install and set it up, and once you do you can forget about it, it just works!

If you are one of my 2 or 3 readers who might had the patience to get to this point with me, be happy this section is over. I will describe in the section below how easy it is to install and setup Nexus as your free-as-in-beer local Maven repository proxy.


To-the-point Nexus installation and configuration

Nexus is released both as a stand-alone server and as a standard WAR file. This section will describe how to install the WAR file release only.

To install Nexus as a WAR file just follow these instructions:

1. You need a servlet container to install Nexus WAR file. While any recent application server should work just fine I only tested it with Tomcat 6.0.20. If you do not have a servlet container I recommend you to download and install the latest stable release of Tomcat 6.x into your build server. For the purposes of this article I will assume you have Tomcat installed in $TOMCAT_ROOT (wherever it is) running on 127.0.0.1, port 8080. Make sure you replace IP address, port and paths on the next steps based on your environment.

2. Download the Nexus WAR file – usually I would recommend you to download the latest stable version but I had some trouble with Nexus 1.4.0 on Tomcat. The previous version, 1.3.6, works fine though and you can get it directly from this URL: http://nexus.sonatype.org/downloads/older/nexus-webapp-1.3.6.war

3. Rename the WAR file to nexus.war – this will make your Nexus portal URL much simpler.

4. With your Tomcat running, copy or upload the file nexus.war into “$TOMCAT_ROOT/webapps” - this should deploy Nexus in just few seconds, as shown in the image below.





If everything worked you should now be able to access Nexus web console in this URL: http://127.0.0.1:8080/nexus/




Click on Repositories link in the left menu to see which repositories are available and their URLs, as shown in the figure below. Nexus comes pre-configured with the most popular repositories including Maven Central, Codehaus and Apache. If your application requires only the most popular libraries the odds are that you may not need to change Nexus' configurations at all. If that is the case, the only thing you need to do is to edit your application's pom.xml to use Nexus repository paths (e.g. “http://127.0.0.1:8080/nexus/content/repositories/central/”). If you want to confirm exactly where each one of these URLs are pointing to or if you need to include new repositories you need to log in as an administrator.




To log in as an administrator and configure Nexus click on the link “Log In” on the top-right portal. It will ask for credentials, to witch you can use admin / admin123.




Once you log in, click on Repositories and select “Maven Central”. As an ADMIN you will see new tabs, click on “Configuration”. In this screen you will find that URL “http://127.0.0.1:8080/nexus/content/repositories/central/” is associated with a remote repository URL “http://repo1.maven.org/maven2/”, the Maven Central public repository. So, in essence, when your application tries to download a library from the Nexus URL that is not in your Nexus repository, Nexus will download it from Maven Central, but the next time it will not need to, since Nexus will keep the library in its local repository.

For my particular project I had to setup 2 or 3 additional repositories in Nexus. That was also easy, I just “cloned” one of the existing entries in the Nexus web console. I then updated the repositories section on my project's pom.xml to point to the repository paths listed in Nexus' web console. I was amazed my project got built successfully the first time, it was so simple even my humble self got it right the first time!

If you tried this but found that I missed some important step this may help - there is much more detailed information on how to install Nexus here: http://www.sonatype.com/books/nexus-book/reference/install-sect-as-a-war.html


References

• Nexus: http://nexus.sonatype.org/

• AppFuse: http://appfuse.org/

• AntHill Pro: http://www.anthillpro.com/

Friday, November 6, 2009

Oracle database quick reference

Similar to the Unix/Linux quick reference post, this one lists multiple snippets about the Oracle database. Feel free to drop a comment with your own Oracle "gems".

# how to list all triggers affecting a table
select * from all_triggers where triggering_event like '%INSERT%' and table_name='PUT_TABLE_NAME_HERE';

# if you get error ORA-24170 when dropping an user see the article below
drop user myuser cascade;
ORA-24170: MYUSER.SOME_QUEUE_NAME is created by AQ, cannot be dropped directly
read: http://forums.oracle.com/forums/thread.jspa?messageID=1184946

# set password for sys/system oracle users
ALTER USER SYSTEM IDENTIFIED BY password;
ALTER USER SYS IDENTIFIED BY password;

# create a full export of an Oracle database:
exp system/password file=database.dmp full=y statistics=none

# import an Oracle database dump file:
imp USERNAME/PASSWORD@ORACLE_SID file=database.dmp full=y
imp USERNAME/PASSWORD@ORACLE_SID file=database.dmp fromuser=ORIGINAL_USER touser=NEW_USER grants=n

# run Oracle imp as a SYSDBA:
imp \'/ as sysdba\' file=database.dmp

# purge and disable Oracle 10g recyclebin tables:
-- login as sysdba
purge dba_recyclebin;
alter system set recyclebin = OFF scope=both;

# list tables with a field with a given name:
select * from all_tab_columns where column_name like '%PUT_A_COLUMN_NAME_HERE%';

# rebuild all Oracle indexes for performance tuning:
select 'ALTER INDEX ' || OWNER || '.' || OBJECT_NAME || ' REBUILD;' from dba_objects where status = 'VALID' and object_type in ('INDEX')

# improve indexes performance:
select 'analyze table ' || OWNER || '.' || object_name || ' compute statistics;' from dba_objects where object_type in ('TABLE');

# Oracle database performance optimizer - run it every time we have significant changes on a database schema
sqlplus /nolog
connect system/
begin
dbms_stats.gather_schema_stats (
ownname=>'PUT_SCHEMA_NAME_HERE',
degree=>3);
end;
/
quit;

# compile all invalid objects in Oracle:
The best way to compile all database objects that are invalid is to use a script in the $ORACLE_HOME/rdbms/admin directory named utlrp.sql. This script finds all objects in the data dictionary that are invalid and compiles them. This script is typically mentioned in patch notes but you can use it any time a schema change occurs.
I also included other alternative approaches just in case.

1. best way:
sqlplus system/password
@$ORACLE_HOME/rdbms/admin/utlrp.sql

2. by schema:
select 'ALTER ' || OBJECT_TYPE || ' ' || OWNER || '.' || OBJECT_NAME || ' COMPILE;' from dba_objects where status = 'INVALID' and object_type in ('PACKAGE','FUNCTION','PROCEDURE') and owner='PUT_SCHEMA_NAME_HERE'
union
select 'ALTER PACKAGE ' || OWNER || '.' || OBJECT_NAME || ' COMPILE BODY;' from dba_objects where status = 'INVALID' and object_type in ('PACKAGE BODY') and owner='PUT_SCHEMA_NAME_HERE';
set pages 50000
spo compile.sql
/
spo off
@compile.sql

3. using the utl_recomp APIs:
connect sys/password as sysdba;
select 'utl_recomp_begin: ' || to_char(sysdate, 'HH:MI:SS') from dual;execute utl_recomp.recomp_serial();
select 'utl_recomp_end: ' || to_char(sysdate, 'HH:MI:SS') from dual;
quit;

# how to enable table shrink in a Oracle 10g database:

alter table mytable enable row movement;
alter table mytable shrink space;

# how to shrink multiple schemas in a Oracle 10g database:

select 'ALTER TABLE ' || OWNER || '.' || OBJECT_NAME || ' ENABLE ROW MOVEMENT;' from dba_objects where object_type in ('TABLE') and owner in ('MY_SCHEMA1','MY_SCHEMA2','MY_SCHEMA3');

select 'ALTER TABLE ' || OWNER || '.' || OBJECT_NAME || ' SHRINK SPACE CASCADE;' from dba_objects where object_type in ('TABLE') and owner in ('MY_SCHEMA1','MY_SCHEMA2','MY_SCHEMA3');

# how to shrink datafiles:
select 'ALTER TABLE ''' || OWNER || '''.''' || TABLE_NAME || ''' SHRINK SPACE COMPACT' from all_tables;

SELECT VALUE FROM V$PARAMETER WHERE upper(NAME) = 'DB_BLOCK_SIZE';

SELECT 'ALTER DATABASE DATAFILE ''' || FILE_NAME || ''' RESIZE ' || CEIL( (NVL(HWM,1)*&&BLKSIZE)/1024/1024 ) || 'M;' SHRINK_DATAFILES FROM DBA_DATA_FILES DBADF,
(SELECT FILE_ID, MAX(BLOCK_ID+BLOCKS-1) HWM FROM DBA_EXTENTS GROUP BY FILE_ID ) DBAFS
WHERE DBADF.FILE_ID = DBAFS.FILE_ID(+) AND CEIL(BLOCKS*&&BLKSIZE/1024/1024)- CEIL((NVL(HWM,1)* &&BLKSIZE)/1024/1024 ) > 0 ;

# how to find which objects have extents at the end of a datafile.
Relocating these objects makes shrinking of relevant datafile possible.

select *
from (
select owner, segment_name,
segment_type, block_id
from dba_extents
where file_id =
( select file_id
from dba_data_files
where file_name = &FILE )
order by block_id desc
)
where rownum <= 5;

Wednesday, November 4, 2009

UNIX / LINUX quick reference

I have compiled the Unix/Linux code snippets below as a quick reference covering the "how to" on various topics. Please feel free to leave a comment with your own "Unix command line gems".

How to:

# list top memory processes on a Linux machine:
ps aux | awk '{print $4"\t"$11}' | sort | uniq -c | awk '{print $2" "$1" "$3}' | sort -nr

# show how many CPUs on a Linux machine:
cat /proc/cpuinfo

# create a symbolic link:
ln -s originalPath newLinkPath
e.g. ln -s /usr/local/apache/logs /tmp/apachelogs

# list largest files in Linux (good for file system cleanup):
find / -type f -size +20000k -exec ls -lh {} \; 2> /dev/null | awk '{ print $NF ": " $5 }' | sort -nk 2,2

# list largest directories in Linux:
du -h / | grep ^[0-9.]*G | sort -g
du -h / | grep ^[0-9.]*M | sort -g | more
find / -type d -size +1G

# split big text files into smaller and more manageable files
split --lines=100000 --suffix-length=3 application.log application.log.a

# redirect Linux output:
ls 1> out.log 2> err.log

# do global string replaces in the VI editor:
:%s/old_string/new_string/g

# set executable tag in shell script files recursivelly:
find . -name "*.sh" -exec chmod +x+x+x {} \;

# delete bak and log files recursivelly:
find . -name "*.bak" -exec rm {} \;
find . -name "*.log" -exec rm {} \;

# recursively determine how much space a directory is taking:
df -h : shows how much space we have on each partition
du -sh * : show how much space the current directory is taking
du -h | grep -v '/' | awk '{print $1}' : does the same without iterating thru the subdirs

# find files that contain a given text string
grep -lir "/data/platform" *

# find files that contain a given text string recursively
find . * -exec grep -li "/data" {} \;
find . * -exec grep -li "/data" {} \; > files.txt

# poll the number of files in a folder every 3 seconds
ksh
while true
do
ls *.retry.xml | wc -l
sleep 3
done

# archive a folder and sub-directories in tar/gz
tar -zcvf archive.tgz directory
e.g. tar -zcvf apacheLogs.tgz /usr/local/apache/logs

# extract a tar/gz archive
tar -xvf archive.tgz directory
e.g. tar -xvf  apacheLogs.tgz .

These are just some of the ones I use the most. You can also find many more at the Unix Toolbox here.

Tuesday, November 3, 2009

Automated handling of header notices in source files

I recently implemented a web-based application that grew from a proof-of-concept into a real solution for a telecom operator, and it has also been offered to other potential clients. And, since it uses only open technologies such as JSF, Spring and Hibernate, it is pretty easy for other developers to reuse it for demos and prototypes without training on proprietary technologies. It is so that other teams in my company have been asking me to share the source code so they too can use it on their own projects.

While I've worked with few developers in the past who don't quite like the idea of sharing "their" code with other teams, I'm quite proud of this app and have no problems sharing it internally if it could help my company. However, to protect my company’s IP I thought I should at least include copyright messages on every single source code file before sharing it. I know I should have included it from the beginning but when we are working around the clock and we do not have to share the code these kinds of things are easily overlooked. So then I had a project with hundreds of classes and other artifacts without any copyright message. That should be a simple and common task to solve, right? Well, I thought as much... but when looking for a good way to handle it I found that my development tools do not have any functionality I could use to easily handle copyright messages on existing projects.

There are many possible ways to automate this task, from SED-based Unix shell scripts to regular expressions in search/replace functions of more advanced text editors, but I wanted to find something easier to use and more well-integrated to my development environment.

After digging for something in those lines I found a good free solution in an Eclipse plugin called Eclipse Releng Tools plugin, or simply Releng. It can be used to automate the task of including a header notice stating the code’s ownership and/or its license. This article will guide you step by step on how to install, setup and use this Eclipse plugin.

But before we start, a note of warning – YOU should make backups before following these instructions, install and run Releng. It did not cause me any troubles but I should not be held liable in any way if it causes you any problem.


Installation

If you still do not have Eclipse installed, download it here. You should select the distribution package that best suits your specific project, or just pick "Eclipse IDE for Java EE Developers" since it works best for most projects. Note that for Eclipse to run you also need a Java Development Kit – and if you do not have it and do not know how to install it you are not the target audience for this article and should probably not follow its instructions.

Once the download is finished extract the ZIP archive and start Eclipse. It will ask for a workspace folder. You can enter the path where your existing project is, or enter something else if you wish to start a new project or check out from a source code repository system. Click on the Workbench icon to close the welcome screen.

Eclipse's welcome screen


Since the Eclipse Releng Tools plugin is not installed by default in Eclipse we must install it now. In Eclipse’s top menu select “Help” / “Install New Software”.
In the “Work with” tab select “--All Available Sites--”. This will list all the available Eclipse plugins. In the filter bar enter “Releng” to filter the results and show only the plugin we need to install. Check the “Eclipse Releng Tools” plugin and complete the installation process.

Eclipse's available plugins window


After the plugin is installed Eclipse will ask you to restart it. Do that so that it is activated when Eclipse comes back up.

Open your project and note that when you right-click the project root you see the new menu item Fix Copyrights. Do not click on it now; this is just to show that the plugin was installed correctly.

Releng's new menu item



Setup

In Eclipse’s top menu select “Window” / ”Preferences”. In the Preferences window click on Copyright Tool. This will present you with the copyright template.

Releng's default copyright template


Replace the default message with this one below, including the empty lines (one at the top and two at the bottom):



This file contains proprietary information of MyCompany.
Copying or reproduction without prior written approval is prohibited.
Copyright (C) ${date} MyCompany. All rights reserved.




Set the year fields to 2009 or the current year.
Optionally you can enable or disable the copyright messages on properties and XML files. You can also instruct the plugin to replace existing copyright messages with this new template.


Usage

Now that Releng is properly setup, right-click on your project’s root node and select “Fix Copyrights”. All of your source code should now include a header message with your notice, as shown in the image below.

Project processed by Releng

Sunday, October 25, 2009

Super Frameworks - develop Java web apps at lightning speeds

In the early days of J2EE (that's how we used to call Java Enterprise Development back then) we had fewer alternatives of technologies, frameworks and reusable components. Web application development was then far simpler than it is today - there was no need for developers to learn a bunch of different things like Spring, Hibernate, JSTL, JSF etc - and things were much simpler to learn and understand. I am not that nostalgic, however, because some big drawbacks compared to what we can do today are that most of what we did was not really reusable (it is hard to consider Copy/Paste as reusable code), we had to spend time writing low-level logic to handle aspects like persistency and logging, code was hard to unit test... the bottomline is that we had to spend more time on infrastructural aspects of our systems than on business logic, essentially killing our productivity and making code quality suffer.

When someone pays you to write a system they want it finished on time and working without bugs. And 99% of the time they have no idea what a JDBC or some other arcane technical acronym is, so they expect you to focus on the screens and public APIs, not in infrastructural code that has nothing to do with visible functionality that they are interested in.

Then few years back we started to see many production-ready frameworks and technologies pop up as new alternatives in our Java development toolkit - far too many actually, but I still think in this case it is better to have more than less. Frameworks and tools like Spring, Hibernate, Struts, jUnit, Ant etc focused on multiple different aspects common to most Java projects like persistency, security, presentation, logging, building and testing, thus improving our productivity.

But then, while this new set of tools helped reduce the need for us to re-invent the wheel it also made the learning curve considerably more steep. Now, just to create a new project we have to install a bunch of frameworks and then integrate each one. It doesn't sound that bad, but let me tell you, it is bad. Instead of wasting time writing connection pools developers now can spend (many) days figuring out why Spring isn't working properly with Hibernate or some other framework. Again, they are not focusing on the business functionality their clients are paying them to deliver.

There are multiple alternative solutions to this problem, each with its own set of advantages and drawbacks. One is to forget Java and move on to another platform like Ruby / Ruby-On-Rails. Instead of a Frankenstein-like system requiring hundreds of independent frameworks patched together, RoR is just one single framework that tries to address most of the aspects I mentioned before. Because of this RoR is more consistent than a bunch of frameworks implemented by different teams. But while many developers love RoR with passion (or perhaps they needed a new theme to sell books?) it is still just a very small niche if we compare it with Java.

A more enterprise-friendly alternative (and therefore one that may help you land in more jobs) is the use of a super framework - which, as the name implies, is a set of frameworks packaged in a pre-configured, pre-integrated manner, with tools to automate redundant manual tasks to improve productivity and quality. There are also dozens of such super-frameworks based on Java but probably the two most known ones are JBoss Seam and AppFuse.

Seam comes packed with more functionality than AppFuse, but it is also less flexible. I don't advocate one over another, but I do believe that if you work implementing web-based Java applications you should consider using something like that. Seriously, after you learn well how to use one of these frameworks you will be amazed how much faster you can do things you did before, like web UI tests, web services, security etc. Not to mention your boss will think you are the fastest developer on Earth, if you do a good marketing of your work.

There are few books available describing both frameworks in detail but you can learn a lot from the project official pages and user forums. There are tutorials you can follow, and the forums have very responsive developers (at least that was my experience) to help answer questions and troubleshoot issues.

I spent a good time learning and working with AppFuse since its version 1.9.x and I can say it was one of the best things I did for my career since I took my first Java certification, back when these certifications were worth something.

Saturday, October 24, 2009

Tools for an efficient development environment

In this post you will find a list of the most common tools and apps I use for software development with a brief description of each.

In the next posts I will describe in more detail some of these tools, especially those that I believe are not that well known. Obviously I am not saying that the tools listed below are perfect for every developer or every situation, nor I am suggesting you should try it (i.e. don't sue me if one of these tools make you sick, kill your cat or something). I am just saying that, so far, they are helping me get the job done.

Lastly, note that each tool may have different licenses (GPL, LGPL, Apache etc) but all are (or have a version that is) "free-as-in-beer" when it comes to simple use.

Development

Eclipse IDE for Java EE Developers - Great editor (or Integrated Development Environment) for Java, JSPs, JSF etc. It used to require hundreds of 3rd-party plug-ins to be decent but since they began bundling it with parallel projects it became truly powerful and way more stable. The only plug-in I find myself installing on a clean instance of Eclipse these days is Subversive, a Subversion client.
Maven - Build manager system. I took some time to get used to Maven after years using Ant but there are just too many cool functions here to let it pass, like built-in online dependencies download, archetypes and hundreds of great plug-ins.
Subversion - SVN is a CVS-like source code versioning and repository system. If you are working on a team of developers you need one of these. But even if you are working alone you need one too. :D
Jenkins (or its former incarnation Hudson) - Continuous integration web portal. Basically you take the time to set it up once and it will pay back in interest every time you have to run a build.
Nexus - This is a maven repository proxy. I will write more about this one in the next posts, but enough to say that if you use Maven you should not rely on the public Maven repositories out there, you need a maven repository proxy. Nexus has a free version and it is powerful and freaking easy to use.
Trac - Trac is a project management, task tracking and WIKI system. I just hoped Trac was based in Java - it is not hard to install it but I guess I'm getting spoiled with tools like Nexus and Hudson that you can install simply by dropping a WAR file in Tomcat's webapp folder. But once Trac is setup it shines - you can easily integrate it with many other tools like Hudson and Subversion.
SoapUI - Use this when you want to run functional tests on your web services. Just do not use it for high-volume performance tests.
JMeter - Use this for high-volume performance tests. I know, SoapUI and LoadUI look nicer and shinier (though I really hate LoadUI's funky UI) but pair JMeter with this and it will save you lots of headaches.

Note: Your development environment gets especially powerful and productive when you integrate tools like Subversion, Trac and Jenkins together to automate aspects like documentation, deployment and testing, and to streamline the communication in your development team.

General

Notepad++ - This is what I use to replace the Notepad application that comes with Windows.
7-Zip - High-performance archiver that also works with almost every format out there.
Agent Ransack - Replacement to the Search function that comes with Windows. I could not hate more that dog that shows up during searches, especially when it does not list files that I KNOW it should be listing (see here for more details on a Windows "feature" in the search function that causes it to not show files under certain conditions)!
WinMerge - Great to compare folders with hundreds of files, like when we want to compare two slightly different local copies of the same project.
FileZilla Client - Great SFTP client.
CCleaner - Remove junk from your disk so you get more available space... and while at it, also remove junk from the Windows' registry. Tip: you can make it even more powerful by dropping this file into CCleaner's path. This will add lots of options to CCleaner (all disabled by default). Just be careful not to set the "enhanced CCleaner" to remove something you might need later.
MyDefrag - Simple, powerful, configurable... best disk defragmenter out there. You can also use Defraggler for quick defrags and leave MyDefrag for big environment updates. Just make sure you don't use any defragger's in your SSD.
Paint.NET - Best free Paint replacement out there.

You can automate the installation of many of these tools with Ninite. This is a great tool that can save you time especially if you use / manage multiple computers and want similar tools in all of them. Go to the website, select the tools you want and download the executable file. Then, anywhere you run this file it will silently install the tools you marked, no questions asked.

You can also use FileHippo Update Checker to keep most of these apps up to date. This app can quickly let you know about updates to most of your installed apps.

And lastly, if you are interested in many more great freeware tools you can find the best ones at the TechSupportAlert's website.


So, this is the initial list. In the next posts I will describe in more details few of these tools, including Hudson, Nexus and SoapUI, and concepts like Build Automation, Continuous Integration etc. If you like this list, a comment would definitely help motivate me to write more. If you find better tools that do about the same of one of the ones I listed, please drop a comment, I am always happy to learn a new trick.

Greetings and my own "get rich" scheme plan

Greetings to you all. Yeah, I know by ALL I meant my still-zero followers, but before I start with my ramblings on Java development and technology I think I should first introduce myself and describe why I think the Internet needs another tech blog.

First, as my personal description states (and where you can find more info about me - though I don't know why you would bother), I am a technology enthusiast who has been working with Java development for more than 10 years. I still remember vividly when Java Server Pages were "the next new thing", and we even had to name extensions of the pages based on the JSPs 1.0 spec like "*.jsp10" because all other JSPs were based on the 0.9 spec. Good times, good times...

But despite that, and my wish to be heard in this channel, I do not want to sound like I am an expert on anything. I just love what I do and I think this blog could be a good tool to keep in touch with like-minded people for a good exchange of ideas. And, if in the process this blog makes me filthy rich with its google ads, then it will be just a mere coincidence - though I think I am overly optimistic on that. Well, I promise if I ever get filthy rich I will write a book (or better yet, pay someone to do it while I spend life in the Caribe) describing how I got rich, and then I will be even richer. Ah if it were that simple... coming back to reality, I guess if your clicks get me one burguer meal per year it will be a burguer more than I expect. Who knows, if I keep writing here years from I could publish this as a book like Joel Spolsky - yeah yeah, I know I am just starting this thing and I am just another developer with a blog, but we gotta dream high, right? :D

My plan for the next posts is to focus on tools and techniques I have been learning or experimenting with, like how to setup an efficient development environment on the cheap (i.e. free-as-in-beer), and more specific techniques related with Oracle databases and Java Server Faces. From there I will keep posting whatever I will be learning / experimenting with in the future.

I will also include here all the sites I read almost everyday, and reviews of the best books I read. Hope you enjoy the ride and help this blog (and its author) with your feedback so I don't feel I'm talking all alone here.

Lastly, I hope you have patience to forgive my obvious lack of English skills - it has been only 3 years, more or less, since I moved to the US. I did not attend school here but went directly to employment, which surely didn't help make me the next Shakespeare. So, bear with me with a little patience and I promise I will try to improve as fast as I can. But if any error passes through the cracks (and I'm sure they will) I will blame MS Word or Google language translator. :D

Yours truly,
Pedro Burglin