Developer's Note

// shall I write some keywords here to boost search engine ranking?

Monday, November 23, 2009

Gant: OutOfMemoryError

Today just hit an OutOfMemoryError when using Gant build script to compile my code.

Google for way to set heap size for Gant, but in the end found the solution by set it in JAVA_OPTS.

set JAVA_OPTS="-Xmx512M"

Monday, September 07, 2009

Redirect Tomcat console output to log file

We know using proper logging library instead of System.out is important. But when there are a legacy application that still using the System.out and System.err, it will be good to be able to pipe it into file for troubleshooting.

The solution is set the swallowOutput="true" in Tomcat context of your webapp. Then this will pipe the stdout and stderr into the logger configured in the same context.

Monday, June 15, 2009

ERROR 1 (HY000) at line 1: Can't create/write to file

MySQL SELECT statement allowed us to pipe the query result in to a file via SELECT ... INTO OUTFILE. It work just fine for me most of the time, until recently I hit this error:

ERROR 1 (HY000) at line 1: Can't create/write to file '\home\myuser\my_output_file.txt' (Errcode: 2) mv: cannot stat `/home/myuser/my_output_file.txt': No such file or directory
The first thing come to my mind is the problem of file permission, so I grant 777 permission to my output directory. But the problem still exist.

Then I check the Mysql username I use, and found that it was granted with FILE permission correctly.

Then I start to google on this error code, and most of the search result point to similars causes.

So I read again the documentation of MySQL, and I found this:
The SELECT ... INTO OUTFILE 'file_name' form of SELECT writes the selected rows to a file. The file is created on the server host, so you must have the FILE privilege to use this syntax.
And the keyword is "server host". I made wrong assumption that it will write file to the server that execute the SELECT ... INTO OUTFILE.

And the workaround is simple, just change my SELECT statement by remove the OUTFILE portion. And pipe the query to file from the MySQL command line
mysql -u myuser -ppassword -h remotehost mydb < myquery.sql > my_output_file.txt
Reading documentation is bored but important :P

Sunday, April 19, 2009

Passwordless SSH login via Public Key Authentication

SSH login with password authentication is often a problem for shell script that run without human interaction. One of the option by simulating user input via some Expect script. While another option is to setup certification based authentication.

Below is the steps:

1. SSH to client host (said with username 'myuser')
2. Generate keys at client host, press 'Enter' while it prompt for key location and passphrase.:


$ ssh-keygen -t rsa

3. Upload the public key generated (~/.ssh/id_rsa.pub) to remote host home directory (said username 'remoteuser')
3. SSH to the remote host with same username ('remoteuser'), create the .ssh folder if not exist

$ cd ~
$ mkdir .ssh
$ chmod 700 .ssh

4. Import public key into authorized_keys

$ cat id_rsa.pub >> ~/.ssh/authorized_keys
$ chmod 600 ~/.ssh/*


Now when the 'myuser' at client host SSH to remote host with username 'remoteuser', it will not prompt for password anymore.

Thursday, March 05, 2009

Duplicate log in log4j

If you have log4j configured as below, you will notice that log entry from "yourLogger" will duplicate in appender


log4j.rootLogger=info, stdout
log4j.logger.yourLogger=info, stdout


To solve this, just change your configuration to:


log4j.rootLogger=info, stdout
log4j.logger.yourLogger=info, stdout
log4j.additivity.yourLogger=false