Enable ANSI colors in Windows command prompt

Company Blogs 14 aprile 2012 Da Igor Spasić Staff

Having colored text in the command  prompt is great thing for spotting error or success messages, especially when you work with git pr. Windows command prompt by default does not have this feature.

But do you remeber ANSI.SYS driver for DOS that enables this? I hope it was not that long ago :))) So I asked myself today, if we had this features back then, why not to have it again today. So I wanted to recode this; fortunatelly i searched first for existing solutions... and I've found a great one: ANSICON.

Do the following:

  1. Download from http://adoxa.110mb.com/ansicon/index.html or https://github.com/adoxa/ansicon
  2. Extract proper files, depending on your windows os: 32bit or 64bit
  3. Install it with: ansicon -i

Thats all. From now on, your windows command lines will be aware of ansi colors.

Read enclosed read me for more options. Note that I tried this on Windows 7 64bit.


git tip: a 'bonsai' tree

Company Blogs 6 ottobre 2011 Da Igor Spasić Staff

Imagine serveral git branches and sub-braches, each with several commits. Although most git UI clients can display a nice branch tree view, it might be not so easy to get an overview at once: some branches start few days/weeks ago and you have to scroll and search to get all info.

I searched for a way to display just branch tree leafs, i.e. to hide all inner commits. to significantly reduce the branch size.

The only solution I found so far is:

gitk --all --simplify-by-decoration

This gives something I call a bonsai git tree. And I like it :)

How I Learned to Separate Test Jars and Stop Worrying

Company Blogs 13 agosto 2011 Da Igor Spasić Staff

Currently, our lib/development folder contains a lot of jars that are actually not used in development. Significant number (or, better, significant amount) is used for tests. Among these is selenium-server.jar, a huge jar that contains also classes from many other used frameworks (bcel, commons.*,  bouncycastle, json…).

So what is the problem with this? If you use IntelliJ IDEA as described in our wiki you will notice that no library is set in the 'Test' scope (available only for the test code). And you might experience the following problems:

  • You are able to use test classes in production code, without any compilation error. For example, you can reference a class from selenium jar, without being aware that class exists only there. And selenium jar is especially a problem here, since it contains all those utilities inside.
  • Your IntelliJ (or any other IDE) may load util classes from selenium jar before it loads them from portal jars. And selenium classes are usually older versions, so compiling from IntelliJ may fails. Afaik this happens regularly when running IntelliJ on Linux.
  • And finally, we are talking about 36+ MB of tests jars vs just 13 MB of development jars:) Your IDE would be thankful for reducing internal cache/indexes size for that many jars and award you with more speed!

Here is one way how to separate test Jars in a graceful way.

[1] The first step is to split development jars in two folders. This is a little batch that does that:

@echo off
set ROBO_PARAMS=/S /MIR /XF /njh /njs /ndl /nc /ns

set TEST_FILES=selenium-*.jar jmock*.jar spring-test.jar tomcat*.jar derby.jar catalina.jar firebird.jar hsql.jar interbase.jar resin.jar mysql.jar ecj.jar ant*.jar jetty.jar  

robocopy portal\lib\development lib\development %ROBO_PARAMS% /XF %TEST_FILES% 
robocopy portal\lib\development lib\test %TEST_FILES% %ROBO_PARAMS%

Not only jars are separated, but above batch also automatically synchronize jars: add new one, delete unused, etc. For linux, you may use rsync to achieve similar behavior.

[2] Go to Project Settings in InteliiJ and add a new library 'test'; then simply attach new lib folders instead of portal ones.

[3] And finally, go to all modules that have dependency on 'development' library and add the 'test' library in 'Test' scope. Move the 'test' library to the bottom of the dependency list. For example:

Note: if you have support-tomcat module, please remove it.

And that is all. Rebuild the project and stop worring ;)

Why is this nice? First, it is just a local fix. Then, we are now safe from selenium issues (explained above). Moreover, test jars are now not included in the exploded artifacts (all 36 MBs of them) -  and therefore not part of the runtime when running server from IntelliJ. And if you are more adventurous, you can create a mirror IntelliJ project with just sources, excluding the tests code and jars – resulting with less memory consumptionand, therefore, more speed.

And best of all, if you want to go back to previous state, just re-attach original portal 'development' folder in the library definition (leave the test library empty).

Quick Start with Liferay Portal

Company Blogs 11 luglio 2011 Da Igor Spasić Staff

Here is a quick step-by-step tutorial on how to get and run Liferay Portal.

Easy as 1-2-3 :) Please share.


JSON: Just Some Outstanding News

Company Blogs 30 maggio 2011 Da Igor Spasić Staff

Some news regarding JSON serialization and exposing service API as JSON web services...

We have a new JSON serialization tool that we call 'loose serialization'. It automatically serializes any object into JSON string, just with a single call. There are some additional features, like include/exclude hints, annotations, transformers... that developer may use to fine-tune JSON serialization process. Read more.

As you already may know, service methods can be called using HTTP request that returns JSON string. We improved this functionality by making this even more developer friendly. Now developer can control which methods will be visible and may pass method arguments in several convenient ways. Read more.

Curious tale of project structure

Company Blogs 7 aprile 2011 Da Igor Spasić Staff

Although this tale is not about folder structure (most developers have it similar), we will start with one. This is how all my Liferay portal project folders look like:

I have several project folders organized similar to this one: for 5.2.x branch, for 6.0.x branch etc. Image shows folder that is dedicated for the trunk. (I obviously love to assign icons to folders for better visual overview;).

This tale will uncover some tricks I am using frequently. Once again, its me who finds these tips useful; its on you to evaluate and decide for yourself:)

Enough of small talk, lets go to the point. There are two things with this structure I would love to share:

1 - Runner to run 'clean' java code without ant and container

2 - Invoke common commands with ease using Launchy


*This tip is mostly for IntelliJ users*

Portal implementaion and definition is split in two modules: portal-impl and portal-services. At the module level, portal-impl module has a 'provided' dependency of portal-service (IntelliJ users will recognize this term:). Meaning: dependency is available in compile time, but not in runtime. This is because portal-service is not deployed with the web application.

When coding some implementation, it would be very cool if we can run it without the container, so we can test and debug it! Due to provided dependency, portal services are not available on running classpath. So, the following code placed in simple Java class with main() method will not run:


Its because portal-service output (jar, classes) is not on classpath when snippet is run.

Therefore, i added another top-level Java module named 'runner'. It is local only, out of SVN. I've made this module depend (with scope 'compile') on portal-impl and portal-service, so both are available on the classpath in compile and run time. Now I am able to run the following code:

new ServiceUtil().setService(new ServiceImpl());

Of course, the running code has to be servlets-api-free, but in most of cases you have some logic layers that are decoupled from the servlets-api.

takeaway: use services and impl code without the ant and container - the code-test-fix cycle is much shorter;)



Launchy is Quicksilver clone for Windows. It may launch files, programs etc with just few keystrokes. Yeah, now you see why all those *.bat files in the root are for:) But problem is that I have several project folders (trunk, v6.0, v5.2...) and the batch file names are the same in all of them. Here comes PyLaunchy and PyDiry plugins to the rescue.

These plugins allow user to assign Launchy shortcut to any folder and to launch directory content. So, for example, I am using following shortcut names:

  • ll for /liferay
  • l60 for /liferay-6.0-ee
  • l52 for /liferay-5.2

etc. That makes me able to invoke any defined batch command on project of my choice. Here is it in action:

Launchy is clever so you do not have to type the complete name:

And there is zero maintenance - just add a new batch for your common work and it will appear in the Launchy list. For a new project, simply copy batches you need to it's root.

For me, this is a faster (only few keystrokes) and more convenient (don't have to navigate to the exact folder, don't have to have IDE on) way to invoke common commands. I use it everyday. Let me give you another example: while i am coding something on trunk, I can invoke SVN update and then ant all and then wlogic deploy on portal 5.2 project, since I know I have to fix some issue there later today. Once when all is done, I can stop with what i was working and switch to the 5.2 project and everything will be ready.

But wait, there is another little trick;) If you are like me, then you hate waiting for ant-deploy or ant-all to finish:) I always try to look at some code while portal is being builded/deployed... and often forgot to continue back when ant finishes its job, ha:) Therefore, for all lengthy batch jobs, I've added little Hotkey notification that gives me a visual and sound information that batch finished with its job:


takeaway: run predefined common operations on desired project with just few keystrokes.

I started a... Application Servers wiki page

Company Blogs 28 gennaio 2011 Da Igor Spasić Staff

... and not a joke:) Application servers wiki document collects informations about appservers Liferay portal can be deployed to. More important are the children pages, with various tips, tweaks, tricks and info. For now, there are some Websphere and Weblogic tips, since those I've been frequently working on. As time goes by, there will be more and more info.

It's not much for the start, but now at least we have s a little place for application servers on the wiki:)

Careful with the XMLStreamReader#getText()!

Company Blogs 19 gennaio 2011 Da Igor Spasić Staff

Let's read the tags content in following XML snippet:


with the single call to (supposing everything is initialized correctly up to this point):


We expect the string 'foo&boo' as result, right?

No! The return value is (or may be) just 'foo'. XMLStreamReader#getText() is allowed to break the text content into several chunks! For above example, we have 3 xml events (of type CHARACTER) sent one after another: foo, &, boo.

Use getText() in a loop to concatenate chunks and retrieve the whole text content. Or use getElementText() :)

JAAS and openLDAP (and Tomcat)

Company Blogs 14 gennaio 2011 Da Igor Spasić Staff

I wrote wiki article about how to configure JAAS that uses OpenLDAP to auth users. Article also announce new feature i.e. portal property: portal.jaas.auth.type that allows JAAS to authenticate users based on their email address, screen name, user id, or login ( determined by the property "company.security.auth.type").

The only problem with current settings described in article is the 403 error once user gets authenticated by jaas. User is authenticated by JAAS, signed in portal correctly, still, the error appears. As I see on the net, others have the very same problem with Tomcat. When I tried the same on WebSphere there was no error. Also, I was playing with the tomcat_users.xml but that didn't  help much. So, until I make a dummy example to see what is going on inside tomcat, i wonder if someone can help:)

Use proper case for JSP tag attributes

Company Blogs 24 novembre 2010 Da Igor Spasić Staff


For JSP tags with dynamic-attributes, be careful to use proper case of defined attribute names; especially if scriptlets are used as attributes values.

Look at following two usages of button tag of liferay-aui tag library:


<aui:button onclick="<%=target%>" value="some value" />


<aui:button onClick="<%=target%>" value="some value" />

On the first sight there is no difference, as it is no difference in HTML. But lets dig deeper.

In (A) we set the 'onclick' attribute. Quick look into the aui TLD tell us that there is no such attribute; instead there is  'onClick'.  Now, what (some?) servlet containers will do? They will assume that  'onclick' is a dynamic attribute; it will be set dynamically in the tag instance; not using the existing setter method. Obvious drawback is performance loss, since no simple setter method is used. Therefore, execution of (A) is slower.

But its not only the performance what is hurt. On some servers, such as Websphere 6, usage of tag when dynamic attribute is used (as in example A) is encapsulated in separated method of the generated jsp class. Unfortunately, scriplet variable will  not be passed to this method, although it will be used in the methods code for setting the value - that combination gives us the compile error! I agree, this might be the app server bug, but we still have the jsp compile error to deal with.

To summarize the drawbacks of not using the proper attribute name case:

  • execution is slower
  • jsp will not compile on some servers if scriptlet is used as attribute(s) value.

So, please, stick with the (B)

Run Portal 6 on JBoss 5.1

Company Blogs 29 ottobre 2010 Da Igor Spasić Staff

Although Liferays jboss-web.xml is set correctly, JBoss 5.1 is still picking up the older hibernate-validator.jar from the commons/lib folder. The exception coming while starting JBoss is:

java.lang.NoSuchMethodException: org.hibernate.validator.ClassValidator.<init>(... 

To solve this issue without touching the commons/lib, add following lines into portal-ext.properties



Fast format-source (for Liferay developers and contributors)

Company Blogs 7 ottobre 2010 Da Igor Spasić Staff

A lot of effort is put into keeping Liferay huge source base formatted consistently, what is very important. There is an advance source formatter (ant format-source) that outputs formatting problems and even corrects some for you. However, since the code base is huge, this task may take several minutes to finishes. Another minor issue is that all sources is scanned, so if someone commit badly formatted source, you will get his formatting problems; his files might be modified and therefore become a part of your changelist.

Some time ago, Zsolt Balogh gave me a great idea: instead of scanning the whole source base, lets just scan the modified files. So that's exactly what I did - and the whole formatting process now takes only few seconds to complete:) Here is my implementation of this idea.

(1) IntelliJ IDEA and plugin Changelist Action.

I've made a little IntelliJ plugin that creates a temp file with list of modified files and then executes user-defined external command, passing the temp file name as an argument.

(2) srcfmt program

A little program that:

  • reads temp file (provided by plugin)
  • copies modified files to some folder
  • invokes liferays source formatting tool on that folder
  • deletes copied files (and move back if modified)

So, formatting will look only on the changeset  files. Here is the current version of this tool (without the jars, use them from portal). Take a look into the .bat for more info. Please note that this is just the first version,so it will change in the future - but the concept stays the same.

(3) And finally...  invocation.

Go to Changes tool window, select the 'Local' tab and invoke the plugin by clicking the icon.

The result appears after few seconds (or less) in a new tool window, as in example below:

I already see some places for improvement and will probably enhance the plugin and the tool in my free time (in my what?:), but, like i've said, the core concept is here and it works.

WebSphere7 emails to GMail - it's all about trust:)

Company Blogs 23 settembre 2010 Da Igor Spasić Staff

By default, Liferay portal deployed on WebSphere7 will not be able to send any email to Gmail, even if the portal is set correctly (pop.gmail.com:995; smtp.gmail.com:465; secure network connection). The reason is that WebSphere doesn't allow usage of untrusted certificates and signers.

smtp.gmail.com has a certificate issued by Equifax Secure Certificate Authority. So, the solution is simple, we need to add this certificate to the trust ones.


1) Download certificate:

wget --no-check-certificate https://www.geotrust.com/resources/root_certificates/certificates/Equifax_Secure_Certificate_Authority.cer


2)  Add downloaded certificate in WS7 admin: SSL certificate and key management > Manage endpoint security configurations > liferayNode01 > Key stores and certificates > NodeDefaultTrustStore > Signer certificates

Read more about SSL configuration

Monitor portal with JConsole attached to WebSphere7

Company Blogs 18 settembre 2010 Da Igor Spasić Staff

When Liferay portal is deployed in WebSphere 7, it is possible to use JConsole to connect to the app server and monitor the portal. You need two files:

(1) wm-jmx.bat

@echo off

:: user configuration

set HOST=liferay:2809

set WAS_HOME=c:/WebSphere/AppServer

set PROPS_DIR=.etc

:: properties

set PROPS=
set PROPS=%PROPS% -Dcom.ibm.CORBA.ConfigURL=file:/%PROPS_DIR%/sas.client.props
set PROPS=%PROPS% -Djava.naming.provider.url=corbaname:iiop:%HOST%

:: classpath

set CLASSPATH=%CLASSPATH%;%WAS_HOME%\java\lib\tools.jar
set CLASSPATH=%CLASSPATH%;%WAS_HOME%\runtimes\com.ibm.ws.admin.client_7.0.0.jar
set CLASSPATH=%CLASSPATH%;%WAS_HOME%\runtimes\com.ibm.ws.ejb.thinclient_7.0.0.jar
set CLASSPATH=%CLASSPATH%;%WAS_HOME%\runtimes\com.ibm.ws.orb_7.0.0.jar
set CLASSPATH=%CLASSPATH%;%WAS_HOME%\java\lib\jconsole.jar

:: start jconsole using was jdk

start %WAS_HOME%\java\bin\javaw.exe -classpath %CLASSPATH% %PROPS% sun.tools.jconsole.JConsole service:jmx:iiop://%HOST%/jndi/JMXConnector

This batch starts JConsole using IBMs VM. First 3 params should be changed to match your environment!

(2) sas.client.props (in PROPS_DIR)







# all false from here





# not needed



That's all, enjoy:)

Portal 6 with Derby DB

Company Blogs 7 settembre 2010 Da Igor Spasić Staff

These are some quick steps how to use Derby DB with Portal 6.

(1) Prepare Portal Database

This shall be done only once.

+  modify derby/bin/ij.bat by adding:

set DERBY_OPTS="-Dderby.system.home=c:\liferay\bundles\data\derby"

+ start ij.bat and create the database:

connect 'jdbc:derby:lportal;create=true;user=liferay;password=liferay';quit;

+ create derby.properties in liferay/bundles/data/derby_opts . This file contains Derby DB settings and may looks like:

# when running embedded mode, also start the network server

# Listen on all interfaces (allow connections from other IPs, not just localhost)

# Turn on authentication - a good move when running network server

# hard code a user/password for username liferay, change to use LDAP or RDBMS users etc...


(2) Integration with portal

+ Add derby.jar to liferay/bundles/tomcat-xxx/lib/ext

+ modify portal-ext.properties to set Derby DB connection:


+ add Tomcat VM parameter for Derby DB home:



When started, portal should print out something like this:

... Determining dialect for Apache Derby 10
... Using dialect org.hibernate.dialect.DerbyDialect


Use portal 6 with app server of your choice

Company Blogs 3 settembre 2010 Da Igor Spasić Staff

Liferay portal can be deployed to many app servers. Cool thing is that from version 6 there are ant targets for downloading and preparing app server of your choice.


(1) Download and prepare app server

Invoke in portals folder:

ant -f build-dist.xml unzip-xxx

where xxx stands for name of your server, e.g.: tomcat, geronimo, jetty.... For full list of available unzipping targets, invoke:

a -f build-dist.xml -p

Server will be downloaded and unpacked to ../bundles folder.


2) Enable app server in build environment

Create/edit file app.server.<user_name>.properties (replace user-name with your os profile name). Note that this file is not under version control. Specify the app server name by setting the app.server.type property, e.g.:


Take a peek in app.server.properties file (and do not modify it!) for possible server values. They should be the same as in previous step.


3) Deploy

Now when the build enviroment is set, invoking ant deploy and ant all will work with your app server.


Freemarker theme templates instead of velocity

Company Blogs 1 settembre 2010 Da Igor Spasić Staff

By default, liferay themes uses velocity templates. For example, classic theme (.../tomcat-6.0.x/webapps/ROOT/html/themes/classic/templates) uses several (*.vm) velocity templates. But Liferay portal may use freemarker templates (*.ftl) instead.

To usee freemarker instead of velocity open liferay-look-and-feel.xml
    <theme id="..." name="...">

and change template-extension  value from 'vm' to 'ftl'.

Since Liferay 6.0 and GA3.

Global ignore files on SVN -or- how to ignore InteliiJ files at once

Company Blogs 1 settembre 2010 Da Igor Spasić Staff

I use IntelliJ IDEA for portal and plugins development. Also, I currently experiment with different project configuration and, therefore, have IntelliJ module files (*.iml) everywhere. For now, I do not want to commit ignore patterns on SVN, but still want to ignore them in my changelist, to have them out of my sight.

For this purpose I use global-ignores feature of svn. This is a client feature and can be set in local configuration file located here:

windows: %APPDATA%\subversion\config  
linux: ~/.subversion/config 

global-ignores setting may look like this:

global-ignores = *.iml desktop.ini


Turn off minifiers and html stripping

Company Blogs 31 agosto 2010 Da Igor Spasić Staff

Portal minifies JS and CSS; and optimizes HTML (by stripping unnecessary characters, etc). Such files are optimized for production, but not for humans :) that dig into the code during development or debugging.

To disable minifiers and html stripping, append the following parameters to the URL line:




Company Blogs 31 agosto 2010 Da Igor Spasić Staff

public class   Liferay   {
String $ = "YIYEEILLI:L" +
"YAoIRRrYFY." ; String $$=


String $$$ ="liferay.com";
byte[] o;int mm,www;public
void portal(){if(o == null
){o= $ .getBytes (); } if(
mm>=$.length()) { return;}


c= $$.indexOf(o[mm++])*16;
while(o[mm] == 32)mm++;c+=
()==++www){www =0;}System.
out.print((char)c); portal
(); }  public  static void
main ( String[] args) {new
   Liferay().portal()  ;}}


javac Liferay.java

java Liferay

Visualizzati 20 risultati.
Items 20
di 1