Thursday, July 2, 2015

[Tomcat][Debug] Start tomcat in debug mode and remote debug java code in eclipse

More often, we need to debug our applications irrespective of the programming language. I need to debug liferay portlets, hooks etc for troubleshooting issues.

Lets see how we can start our tomcat in debug mode and debug with eclipse. Follow the simple steps.

1. Open catalina.bat in tomcat/bin folder.

2. Search for the line starting with set DEBUG_OPTS=

3. Replace the line with
set DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044

4. Port number given here is 1044, you can choose any port as per the availability.

5. Now start your tomcat by running catalina.bat. Tomcat logs should print this line at the start
Listening for transport dt_socket at address: 1044

6. In the eclipse, you can do remote debugging, Go to Run > Debug Configurations, under Remote Java Application, create a new node and make sure to change port number for debugging.

All done. Your application is ready for debugging.

Until next time, C ya.


Wednesday, July 1, 2015

[Liferay][JSTL] Adding JSTL support for liferay portlet.

Hi,

It a good practice to use JSTL for your portlets jsp rather than using scriptlets. This blog will show how to add support of jstl for your portlets. Follow these simple steps -

1. Add portal-dependency jars to lifeary-plugin-package.properties file

portal-dependency-jars=\
    jstl-api.jar,\
    jstl-impl.jar,\

2. Add portal-dependency tlds to liferay-plugin-package.properties file.

portal-dependency-tlds=\
    liferay-portlet_2_0.tld,\
    liferay-ui.tld,\
    fn.tld,\
    c.tld,\
    fmt.tld

3. In the JSP add taglibs.

<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

4. And now you can use <c:xx />, <fn:xx/> and <fmt:xx> and similarly other taglibs.

Hope this helps.

Until next time. C Ya

[PHP] PHP not working | Code not being executed by apache.

Hi,

I had this problem yet to be resolved. I tried easyphp, zpanel but php did not work for me. I could see my php code in page source in browser. My apache was actually not executing php code as php, rather it was taking as simple html.

To solve this problem, follow the steps below.
1. Check if php is really installed and available. Open command prompt anywhere and execute php -version

This should return something like this.


If you're unable to see, add php to path.

2. Check if php module is added in httpd.conf of your apache. Something like this should be present
LoadModule php5_module "C:/zpanel/bin/php/php5apache2_4.dll"
PHPIniDir "c:/zpanel/bin/php" 

3. Check if AddType is added and uncommented in httpd.conf. If this is not present, add it.
AddType application/x-httpd-php .php

Apart from these, just check the file extension, it should not .php and not accidently saved as .php.txt. And if you're using short tags <? then short tags should be allowed. To allow php short tags follow this post

Hope this helps.

Until next time. C ya.

Tuesday, June 2, 2015

[MySql] Importing Data to Mysql From SQL file

Hi,

Its very often that we need to import data to mysql. Sometimes we have database already created, sometimes does not.

Below is the syntax to import data. When we do have a database already created and want to use that.
mysql -u ravi -p mydatabasename < databasefile.sql

This will prompt for password and import data to mydatabasename.

When we do not have a database already but create database command is written in the file and the same database is used.
mysql -u ravi -p < databasefile.sql

This will also prompt for password because we used -p option which is for password. For username we used -u. Remember that if we want to create a database then user should have appropriate permissions.

That's it.

Hope this helps someone. 

Wednesday, May 6, 2015

[Liferay] Writing Custom Sql for multiple tables in Liferay

Hi Friends,

There were a number of times you might have faced a situation when you need data from multiple tables. Sometimes you would have got the data from one service, extract some data and then call another service, extract some more data and do the processing by writing some logic. Well, this has a major impact on performance and that's not good.

That's not good choice because you can write your own custom SQL query and get the desired result. The query we are writing, we always have a chance to optimize it and boost/improve performance. Alright, enough of the lecture.. lets get to work.

Friday, May 1, 2015

[Liferay][iPad][iPhone] Safari turns numbers into links

There are many calling applications which install some kind of plugin to turn numbers to links on which if you click will offer you to call. Skype's click to call is one of such application.

Well Safari, by default does this. We did not like it. You also don't, probably that's why you're here.. Here is the solution.

Open the theme or template or html file and add this meta tag.

<meta name="format-detection" content="telephone=no">

This will leave all numbers as it is. Now, you may also want to show some phone numbers as link which were actually phone numbers. In this case use like this.

<p>My phone number: <a href="tel:1-203-203-2020">1-203-203-2020</a></p>

This will show the phone number as link.

In case of liferay, open your theme's portal_normal.vm file and add the meta tag as mentioned above.

Hope this helps.