Friday, May 30, 2008

Funny Unix Symbolic Link to Windows Server issue

I faced this while doing deployment of one system to a unix server.

There is a folder/directory which is the symbolic link to a folder hosts at a windows NT server.

It is meant for clustering. The idea is 2 servers put the files/documents at the same folder at one location.

So, everytime i build my source code and deploy the war file at the unix server, i will run a program which runs the data migration. During the process the program will make use of the "open office service" that resides behind the operating system to create document such as Word and put at that particular folder as mentioned above.

Nightmare came. System kept throwing errors. The error message said it has something to do with "wrong code blar..".

I thought it was due to my code. Then I spent days to investigate the problem and to examine my code. It was a wrong move, a waste of time because in the end i found out that it is actually the program failed to create new directory! Ok reason found. The funny thing is, i tried to create the directory using unix shell command manually but failed! I did a list files command and found out that there is no such folder! But why did Unix say the folder is there? Ain't it funny!

Later i discovered that the folder is actually hidden. However i still did not manage to remove the folder by using the "rm -f ." command. From the net i know that this command works all the time to remove hidden directory. Clearly it did not work out in my case. So how now?

Finally i recreated the directory that the Unix claimed exist at the Windows Server, which is the "parent" cluster machine that holds the folder. After that i removed the folder again from the Shell at the Unix server. Yahoo! This time everything is back to normal! My program ran successfully!

What a waste of time. Was in the wrong direction. The Open Office Service should throw a more "exact" or "meaningul" message.

Nevertheless, I still do not know WHY and HOW did this problem happen! I only know the solution so far!

Thursday, May 29, 2008

Somthing about Set in Java

Well, if you read about the Java API, you will know that Set will only add object that does not exist in the Set itself. You must be aware of this especially when working with Hibernate! Here's my experience:

I was trying to add a few objects in a Set and set this Set. Then I found out from the database that there is always only ONE object added. I did a debug and found the size of the Set is always > 1 !!!

What happened? Here is my answer from torough checking:

Only the 1st object had been added to the Set. It is because the rest are actually "equal" to the first object so Set does not take them anymore! Bear in mind that each object differs from each other using their ID field. They do have their own ID yet when they are being added into the Set so they are rejected by the Set!

Thus, i have to save each object first before adding them into the Set. The reason is the ID will be generated by Hibernate for each object. The Set knows that they are NOT EQUAL right now then they will be added.

Tuesday, May 13, 2008

Apache POI

I have one web application, everytime i deploy i will need to load initial reference data again and again.

The amount of these data is huge!

I used to hardcode all these data in my Java file. I organised them properly using data structure such as String array and so on. In my Java file i have a few functions that actually perform the data loading job.

The problem is, It's time consuming and error prone to hardcode each and every data in the Java file.

Therefore, today i decided to put all the data in Spreadsheet program. It is easier to maintain data at Spreadsheet rather than in the Java file itself.

Then i used Apache POI library to read me those data from the Spreadsheet (Microsoft Excel).

Just one time try and it worked fine!

So simple! I was really delighted!

Wednesday, May 7, 2008

One day effort for unknown vm crach of Eclipse during Subclipse installation

WTF,

It took me one day to get the problem fixed. The solution is so simple!

I setup Eclipse at my new laptop. As usual, i also installed the Subclipse plugin. By right it should work properly. Well, when i tried to create a new remote source repository using Subclipse Perspective in Eclipse, Eclipse just quitted suddenly followed by a prompt saying that it is some kind of memory crash.

Also, there is an error log file generated each time Eclipse exited. However the message is so so not comprehensive.

Here's the message:


## An unexpected error has been detected by Java Runtime Environment:
## EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x3b397bfc,
pid=3824, id=5160
## Java VM: Java HotSpot(TM) Client VM (10.0-b22 mixed mode
windows-x86)
# Problematic frame:# C [libapr-1.dll+0x7bfc]
## If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.


With this only clue, i kept Googling for the whole day and still did not get the problem fixed! How frustated was i!

Besides trying out the solutions found online, I also tried to tackle the problem by doing a few times of trial and error, which is actually install-uninstall this kind of stuff.

We really got to be patient enough when dealing with this kind of problem.

Yet, the problems stayed. All the tries did not bring positive outcome.

Office hour ended. Today i did nothing but just configuring stupid Subversion on Eclipse. Boss, please don't get mad.

I started over the puzzle solving game again at home after coming back from dinner.

With calm mind, and of course enough of rest, i found the answer within an hour!

I came across this article online:

http://subclipse.tigris.org/faq.html#win32-crash

Here's the excerpt:


As soon as I do something with Subclipse on Windows, Eclipse just
crashes. Why does this happen?



This is a fairly recent problem that is caused by a DLL incompatibility. Subversion uses a library called APR or the Apache Portable Runtime. This library has a component called APR-ICONV which is used for translating characters in path and file names to/from UTF8 and the local character set. The release of Apache 2.2 brought with it new releases of APR and APR-ICONV and these are not binary compatible with previous releases.

Subclipse ships with the Apache 2.0 version of these libraries. This crash
occurs if you install an application that installs the Apache 2.2 version of
these libraries AND ALSO sets the APR_ICONV_PATH environment variable to a path that contains the Apache 2.2 version of the APR-ICONV .so objects.



The fix is actually simple. Change the name of the environment variable to APR_ICONV1_PATH. The Apache 2.2 library will look for this environment variable name first, and only fallback to the older name if it is not found. You can safely have an APR_ICONV_PATH environment variable pointing to the Apache 2.0 version of these libraries and the APR_ICONV1_PATH environment variable pointing to the Apache 2.2 version. Subversion 1.5 has resolved this problem by discontinuing the use of APR-ICONV. Instead, Subversion will use translation routines that are provided by the Windows operating system.


So, i uninstalled the Subversion Server built against Apache 2.2 and replaced it with the one built against Apache 2.0.

Eclipse looks fine now.

Finally!