Monday, November 17, 2014

How to replace HTML tag with ant

To replace a word or character with Ant,
we can use the following command.

<replaceregexp file="{FILE_TO_REPLACE}"
    replace="{WORD}" flags="g" byline="true" />

But the above command can use to replace words withouth xml/html reserved characters only.
To replace words with xml/html reserved characters,

1. encode the xml/html reserved words before putting into the the <replaceregexp /> command.
eg, <a>link</link>  =>  &lt;a&gt;link&lt;/a&gt;

2. put the encoded words into <replaceregexp />

<replaceregexp file="{FILE_TO_REPLACE}"
    replace="&lt;a&gt;new_link&lt;/a&gt;" flags="g" byline="true" />


Saturday, November 8, 2014

Scheduling with EJB

There is an easier way to schedule a job with EJB.
What we need is the EJB implementation and most important is the action method to be run.

@Stateless(name="serviceLookupName", mappedName="serviceLookupName")
public MyEjbServiceImpl {

    @Schedule(dayOfMonth = "*", hour = "00", minute = "01")
    public void myScheduledMethod() {
        // action to run


The advantage of this EJB schedule is easy to implement,
as just need to add the @Schedule annotation to an EJB method.

But the disadvantage is the scheduled time is hard to change,
if user wishes to change the time for the scheduler to run,
the source code need to be changed, recompile, and deploy.

for more information about the scheduler, please refer the official page.


Thursday, November 6, 2014

reading java.util.List in velocity template

Assuming a list pass to the Velocity context.

List list = new ArrayList();

VelocityContext context = new VelocityContext();
context.put("list", list);

To get the list value,
below is the syntax in Velocity template





Wednesday, November 5, 2014

How to convert sql date to util date

private String convertSqlDateToUtilDate(java.sql.Timestamp sqlDate) {

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");

Calendar utilDate = Calendar.getInstance();


return sdf.format(utilDate.getTime());



Related Posts Plugin for WordPress, Blogger...