Open a website in a browser from commandline

My attempt to open a website in command prompt or a batch file.

I found that, for Windows, I could run


In batch script, I can do:

start explorer

Ps. Actually, I don’t really have to use start 🙂

In Linux, we should be able to run


(if there is Firefox)

Java JDK 6 also supports it using Browse class:


Installing Fedora 3 on Windows

This is a record of my attempt to install Fedora 3 on Windows

1. Install JDK 6. Can be downloaded from:

1.1 In order to prevent spacing problem in the directory name, I chose to install Java at C:\Java (Normally, it goes to C:\Program Files\Java

2. Install fedora 2. It can be downloaded from:

2.1 Navigate to folder in Command Prompt (cmd.exe). I ran the Command Prompt as Administrator by right click > Run as Administrator. Then I run

java -jar fedora-installer.jar

2.2 I selected custom and parameters [roughly] can be found here.

3. Setting Environment Variables. This can be done in 2 ways.

3.1 Right click at My Computer > Properties >Advanced >Environment Variable

3.2 Through command (only for that session)



SET CATALINA_HOME=C:\fedora\tomcat

3.3 Navigate to FEDORA_HOME\tomcat\bin

3.4 Run startup.bat

Please find your fedora at the url, for example, http://localhost:8080/fedora

Ps. It also works when setting up java to C:\Program files\Java\…

Pss. Everything seems to work fine, there must be something wrong with my installer lol

Escaping HTML in Java

Today I was looking around for ways to escape HTML in java, similar to htmlspecialchars() in PHP.

I found this Lang package:

To use it:

1. Download the jar file and put it with other libraries in lib

2. Import “org.apache.commons.lang.StringEscapeUtils;”

3. StringEscapeUtils.escapeHtml(myString);

API/Documentation can be found here:

Fedora add datastream Exception

Today, when I deployed my application on a production server and tested it, I received this exception:

fedora.server.errors.GeneralException: Unable to add or modify object (commit canceled)

This is caused by fedora.API-M.addDatastream() method. It turned out that the issue is because I used null value for an alternateid, instead of an empty array of string. This is quite strange because everything works fine on my development machine. Anyway, this is the correct syntax.

apim.addDatastream(“changeme:1”, “DsId”, new String[] {}, …);


apim.addDatastream(“changeme:1”, “DsId”, null, …);

Source: [1], [2].

Casting Array in Java

Casting an array directly throw ClassCastException. This is how I get around it.


import java.util.ArrayList;

ArrayList<MyObject> tmp = new ArrayList<MyObject>();

// insert data in to tmp

// this will prompt and ask for casting

MyObject[] tmpArray = tmp.toArray();

// this will throw ClassCastException

MyObject[] tmpArray (MyObject[]) tmp.toArray();

Why? Because toArray() returns a type of Object[] and it requires type casting.


MyObject[] tmpArray (MyObject[]) tmp.toArray(new MyObject[tmp.size()]);

I guess it should be the same for other dynamic list types.

Rename Java Package in Eclipse

Today, I attempted to change a java package name. I did a right click at the package name and there’s no “Rename.”

What I did is creating a new package, say Then I go to, right click > refactor> move and select

I then edited web.xml file, do a search replace from to and it works.

However, later I found that there’s a function “rename” under refactor. but I have not tried it. I will check it out next time.

Installing UTF-X on a Mac

This is a record of my first attempt to install UTF-X, XSLT Unit testing framework, on Mac OS X. This is a link to UTF-X’s project page:

Note that the steps are based on RUBRIC’s documentation.

1. Installing JDK from

2. Installing apache ant from

2.1 Download and Unzip to a directory, say ~/ant/

2.2 Add ant/bin to System Path

2.2.1 vi .profile then add “EXPORT PATH=$PATH:/path/to/ant/bin”

2.3 Create a new system variable “ANT_HOME” with a value “/path/to/ant”

2.3.1 vi .profile then add “EXPORT ANT_HOME=/path/to/ant”

2.4 Create a new system variable “JAVA_HOME” with a value “/path/to/java” for example “/Library/Java/Home”

2.4.1 vi .profile and add “EXPORT JAVA_HOME=/Library/Java/Home”

2.5 run source .profile to use those variables

3. Installing UTF-X

3.1 Download and Unzip to a directory, say ~/utf-x

3.2 Compile UTF-X samples by running “ant samples” via Terminal

Ahh it works.