Wednesday, April 29, 2009

Migration to liferay 5.2.2.: ServiceContext, JAVA_HOME, 7cogs, Cannot allocate memory

Migration to 5.2.2 continued:

Ok friends - here are some of the pitfalls I encountered. I hope it helps some of you who read this.

1. JAVA_HOME

Coming from JBoss it was quite a surprise to me to get the good old "JAVA_HOME not defined" error message. So I had to search where to set point it to in my linux (ubuntu 6.06) based virtual private server environment.

Finally I found out that the following path seemed to be a good one:
JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun

(Note: The full command to set the parameter is "export JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun" )

2. java.io.IOException: java.io.IOException: Cannot allocate memory

Also an old friend. The main trick was just to lower the memory that java would get.
So I set in the setenv.sh file the following:

JAVA_OPTS="$JAVA_OPTS -Xmx192m -XX:MaxPermSize=128m -Xms128m -Dfile.encoding=UTF8 -Duser.timezone=GMT -Djava.security.auth.login.config=$CATALINA_HOME/conf/jaas.config -Dorg.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES=false"
(Note: The little linux command free -m helped a lot identifying the problem)


3. The new ServiceContext approach

Finally after the server started running I realized some errors in my own code (yes - the great JSF portlets :) ) due to simplifications of the liferay API.

Liferay has moved some repetitive context related attributes into an own ServiceContext class

In detail I changed my code from

BlogsEntryLocalServiceUtil.addEntry(liferayUser.getUserId(),
themeDisplay.getPlid(), this.getName(),
this.getEntryText(), now.get(Calendar.MONTH), now
.get(Calendar.DAY_OF_MONTH),
now.get(Calendar.YEAR), now.get(Calendar.HOUR), now
.get(Calendar.MINUTE), false, true, trackbacks,
tags, true, true, themeDisplay);
to the following:

ServiceContext serviceContext = ServiceContextFactory.getInstance(BlogsEntry.class.getName(), req);

BlogsEntryLocalServiceUtil.addEntry(liferayUser.getUserId(), this.getName(), this.getEntryText(),
now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH), now.get(Calendar.YEAR), now.get(Calendar.HOUR), now.get(Calendar.MINUTE),
false, true, trackbacks, serviceContext);


4. Removal of 7cogs example data

As you might have noticed the new version of liferay comes along with some example data. That is a great idea - especially for beginners. Also it shows the new features of the WOL-portlet. ("World of Liferay" :) )
Unfortunately it is a bit tricky to remove the sample data afterwards. Even after removing the hooks - the data stays in the DB of course. And unfortunately it overwrites your default "instance" (that is your first website / company id)

So what I did is:
  1. Restore my VPS backup :)
  2. Remove the 7cogs folder before the first server start

I hope my migration posts help you. As always: I'm happy about all feedback and follow up questions.

No comments:

Post a Comment

I'm happy about every feedback! :)