« Back

Debugging Liferay in Eclipse

Company Blogs September 22, 2010 By Ray Augé Staff

When should you use a debugger during development? At ALL times! At least that's my view.

Isn't that a hassle? Well debugging sure can be, but if you setup your environment in a specific way, it can actually become very fast and almost transaprent. I like transparent!

Here are steps I take to configure my tomcat (I've followed the same steps with JBoss):

  1. Note the deployment path of tomcat (in my case I'll use /bundles/tomcat-6.0.x)
  2. In Eclipse, open the "Run Configurations" manager (Run -> Run Configurations...)
  3. On the "Java Application" node, right click and choose "New".
  4. On the first tab (Main) select the project you are running in tomcat
  5. In the Main Class field enter org.apache.catalina.startup.Bootstrap
  6. On the Arguments tab, in the Program Arguments field enter start
  7. In the VM arguments field enter the following:

    -Xms1024m
    -Xmx1024m
    -XX:PermSize=128m
    -XX:MaxPermSize=256m
    -XX:+CMSClassUnloadingEnabled
    -Dorg.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES=true
    -Dcatalina.base=/bundles/tomcat-6.0.x
    -Dcatalina.home=/bundles/tomcat-6.0.x
    -Djava.io.tmpdir=/bundles/tomcat-6.0.x/temp
    -Dexternal-properties=${workspace_loc:<NAME_OF_YOUR_ECLIPSE_PROJECT>}/portal-web/docroot/WEB-INF/src/portal-developer-tomcat.properties
    -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
    -Djava.util.logging.config.file=/bundles/tomcat-6.0.x/conf/logging.properties


    You many notice that I included a reference to my portal project's portal-developer-tomcat.properties file. This way I can change portal settings and only need to restart the portal without a redeploy, which is very convenient.

    You may also notice that I included tomcat's juli log manager so that all the normal web app configurations work as expected and in the Eclipse console, which is also very nice.

    Adjust your heap settings as desired, but the above settings have worked for me in 99.999% of cases.
     
  8. In the Working directory field choose "Other" and enter /bundles/tomcat-6.0.x/bin. Notice that this is the tomcat path, plus the /bin folder.
  9. The JRE tab should be already set properly, but you can choose any JRE that is installed that is 1.5+.
  10. On the Classpath tab, remove any entries under User Entries and then choose "Add External JARs...".
  11. Select the 3 jars located in /bundles/tomcat-6.0.x/bin.
  12. On the Source tab make sure that you have both Default, as well as your project in the list.

    Optionally here you can add any plugin projects that you are working on, as well as adding the path to the jsp java classes (typically /bundles/tomcat-6.0.x/work/Catalina/localhost/_)
  13. On the Common tag choose at least Debug and Run under "Display in favorites menu".
  14. Click "Apply" near the bottom of the dialog.
  15. Finally, to start the portal in debug mode, click the Debug menu in the Eclipse toolbar, and choose the run config you jsut created.

    You should see at this point output on the Eclipse console showing that tomcat is starting up.

I've been using this techinque for at least 3 years and I run the portal this way 99.999% of the time. By doing so, I can at any point in time add a breakpoint and start trouble shooting and I don't have to worry about re-connecting to or restarting the portal in debug mode, I know it's already done.

If you want to add any other java apps this way, the simples technique is to first run the app in the traditional way, then observe the process log to see what the full command that was actually used to start it, and from where. Once you know that, you can add any app to Eclipse Run Configuration.
 

 

Threaded Replies Author Date
Hey Ray, I use to work in a different and IMO... Thiago Leão Moreira September 22, 2010 9:38 AM
I started this way long ago. I dropped it... Ray Augé September 22, 2010 9:50 AM
@Ray Can you explain step by step your... Denis Signoretto September 24, 2010 3:46 AM
Besides the configuration above, can you... Ray Augé September 24, 2010 7:47 AM
@Ray Hi ray, you are right I was't really... Denis Signoretto September 24, 2010 9:38 AM
Got it! I simply meant "the method that I... Ray Augé September 24, 2010 9:43 AM
nice post! Thank you, Ray Jonas Yuan September 22, 2010 11:45 AM
Hi Ray! It's good to see this stuff written... Vilmos Kozma September 23, 2010 6:53 AM
You can do hot code replacement using this... Ray Augé September 23, 2010 8:39 AM
How should i hot-code replace classes? I know... Corné Aussems March 18, 2011 1:33 PM
Eclipse should do it automatically. Of course... Ray Augé March 18, 2011 1:38 PM
Oh, as I learned the hard way last week, jsp... Ray Augé March 18, 2011 1:39 PM
Hi, you can combine your ideas. Extend VM... Daniel Niklas November 11, 2010 1:17 AM
It works GREAT! Thanks! Tamas Imrei November 16, 2010 2:33 AM
Since I can't see my portlet on the website, it... Its Me January 24, 2011 8:57 AM
I just found out by trial that when in the... Corné Aussems March 28, 2011 2:26 PM
Just testing and got an error using helios SR2 ... Michel Wicky May 14, 2011 12:35 AM
You still seeing this? I wonder if eclipse... Ray Augé May 17, 2011 6:25 AM
I updated it to just say... Ray Augé October 24, 2011 7:14 AM
hi sir. pls tel me how to configure liferay... Babu Reddy K V March 22, 2012 4:13 AM
I would do basically the same thing as above... Ray Augé March 22, 2012 6:12 AM
Creating my project of, 'portal', with the,... Linus Sphinx April 11, 2012 2:22 PM
Does this method of debugging in Eclipse no... Mary Mizrahi May 24, 2012 5:59 PM
I have no idea with respect to the IDE, but I... Ray Augé May 25, 2012 12:37 PM
You are a genius !!!! Thx Jacques Traore February 5, 2013 12:38 PM
this method is debug for portlet, theme, ext,... hiep lq June 11, 2013 9:04 PM
This method works for the portal, but you need... Ray Augé June 12, 2013 10:53 AM

Hey Ray, I use to work in a different and IMO more efficient way. I start my Tomcat in a remote debug mode, just call from command line the command: "catalina.sh jpda run" . Then you can connect your Eclipse to Liferay using the "Debug Configurations > Remote Java Application" menu. By default the host and port points to the correct place. You can also disconnect as you wish and continue the normal testing. Give a try and let me know.

um abraço!
Posted on 9/22/10 9:38 AM.
I started this way long ago. I dropped it because it caused me to have to editing the tomcat configurations all the time, setting different VM settings, etc. With the method I use, I can duplicate the run config, and change only a few settins, such as adding JMX, or particular GC settings, etc., all without touching the files in the bundle. I can even switch to different installed JVMs configured in Eclipse without having to edit more config, or change the system PATHs or settings.
Posted on 9/22/10 9:50 AM in reply to Thiago Leão Moreira.
nice post! Thank you, Ray
Posted on 9/22/10 11:45 AM.
Hi Ray!

It's good to see this stuff written down. However, for the whole picture it would be nice to hear about hot code replacement. When I debug my code and find something to be fixed I like not having to run any build script to test the new code. So is the above description solves this issue or we need to do some extra work to get the JVM to hot code replace?
Posted on 9/23/10 6:53 AM.
You can do hot code replacement using this technique. There is of course the limitation of the (Sun) JVM, which does not allow new|changes to the class's public signature.

Oh, and the project does have to be listed in the sources tab of the run configuration.
Posted on 9/23/10 8:39 AM in reply to Vilmos Kozma.
@Ray

Can you explain step by step your method?

Thanks,
Denis.
Posted on 9/24/10 3:46 AM in reply to Ray Augé.
Besides the configuration above, can you explain a little what "method" you'd like me to clarify? I'm not quite sure what you're asking, but I would like to give a good answer.
Posted on 9/24/10 7:47 AM in reply to Denis Signoretto.
@Ray

Hi ray, you are right I was't really clear. I'm referring to your sentence "With the method I use". I 'm guessing it's the same of Thiago.

Thanks,
Denis.
Posted on 9/24/10 9:38 AM in reply to Ray Augé.
Got it! I simply meant "the method that I described above in the blog post".
Posted on 9/24/10 9:43 AM in reply to Denis Signoretto.
Hi,

you can combine your ideas. Extend VM arguments to
-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n

So you get the advantages metioned by Ray and you can use "Remote Debugging" as Thiago has described.

Daniel :-)
Posted on 11/11/10 1:17 AM.
It works GREAT! Thanks!
Posted on 11/16/10 2:33 AM.
Since I can't see my portlet on the website, it isn't deployed to the server? How can i do this in eclipse?
Posted on 1/24/11 8:57 AM.
How should i hot-code replace classes?
I know there is deploy-fast for jsps and deploy.properties.
Posted on 3/18/11 1:33 PM in reply to Ray Augé.
Eclipse should do it automatically. Of course you can't add new methods, but changes should be pushed automatically as soon as you save, while in debug.

Just make sure to include their path to the jsp java source in the run configuration (that is in the "work" folder, /work/Catalina/localhost/*/).
Posted on 3/18/11 1:38 PM in reply to Corné Aussems.
Oh, as I learned the hard way last week, jsp pre-compile breaks the ability to debug them, so don't do that.

They have to be compiled inside the debugged JVM.

I even tried pre-compiling them with debug flags added, but it still didn't work. Anyone with insight in that please let me know.
Posted on 3/18/11 1:39 PM in reply to Ray Augé.
I just found out by trial that when in the Servers View you add a Tomcat Server or Liferay Server (IDE/Studio) and point it to your newly build bundle and just under Open launch configuration >> Source >> Add : Java Project >> The portal project.
Start in debug and voila..
Posted on 3/28/11 2:26 PM.
Just testing and got an error using helios SR2

Variable references non-exitent resource: ${workspace_loc:portal}
Posted on 5/14/11 12:35 AM in reply to Corné Aussems.
You still seeing this? I wonder if eclipse changed the default variable names!
Posted on 5/17/11 6:25 AM in reply to Michel Wicky.
I updated it to just say ${workspace_loc:<NAME_OF_YOUR_ECLIPSE_PROJECT>}

Replace that token with whatever is the name of your eclipse project. OR just replace that entire variable with the absolute path to your project.
Posted on 10/24/11 7:14 AM in reply to Ray Augé.
hi sir.
pls tel me how to configure liferay with Jboss to eclips
Posted on 3/22/12 4:13 AM.
I would do basically the same thing as above and get the start command used by jboss, and setup the run config something like this:

http://i.imgur.com/Gjqyv.png
http://i.imgur.com/joTTR.png
http://i.imgur.com/­m8mY5.png
http://i.imgur.com/6wZTX.png

Note the ${JBOSS_510_DEPLOY} Eclipse variable points to the JBoss install location.
Posted on 3/22/12 6:12 AM in reply to babu reddy.
Creating my project of, 'portal', with the, "Create from ant build file", option, all works, see the app, create the run configuration and fire i
t up just fine but I don't see any source to step through, just all the jars. How do you create your project in eclipse?
Posted on 4/11/12 2:22 PM.
Does this method of debugging in Eclipse no longer work with 6.1 and IDE 1.52?
For some reason I no longer get output to the console from my portlets and break points are ignored.
Posted on 5/24/12 5:59 PM in reply to Linus Sphinx.
I have no idea with respect to the IDE, but I still use this same technique with 6.1 and trunk.

Have you included the plugin projects in the sources list of the debug configuration?
Posted on 5/25/12 12:37 PM in reply to Mary Mizrahi.
You are a genius !!!!
Thx
Posted on 2/5/13 12:38 PM in reply to Ray Augé.
this method is debug for portlet, theme, ext, hook project?
when i use liferay. I use web-content and cms script.
my code find service is return nothing. i want debug into serviceLocator.findService.
howto setup enviroment for debug portal code?
Posted on 6/11/13 9:04 PM.
This method works for the portal, but you need the source to make it useful.
Posted on 6/12/13 10:53 AM in reply to hiep lq.