ZeroTurnaround Support Forum » JRebel Development and Plugins

How to reload Struts 2 properties?

(9 posts)
  • Started 1 year ago by rubens_gomes
  • Latest reply from Aneesh

  1. I am developing a web application using Eclipse and Tomcat 6.0.18. I would like the Struts 2 (i18n) resource.properties file to be reloaded when changed.

    Does anyone know how to get properties file to be reloaded ?

    I do not want to restart the Tomcat server everytime I make a change on the resources.properties file. Also, I do not want the Tomcat context to be reloaded for resources.properties changes. I think at some point in the past I was able to get this to work using javarebel.

    Here is my configuration. I have tried different javarebel versions, struts plugins to no avail.

    -noverify
    -javaagent:C:\java\javarebel-nightly-dev\javarebel.jar
    -Drebel.plugins=C:\java\plugin\trunk\target\javarebel-struts20x-plugin-1.1-M1.jar
    -Drebel.struts2-plugin=true
    -Drebel.spring_plugin=true
    -Drebel.log=true
    -Drebel.log.file=C:\tmp\lista\logs\javarebel.log

    Posted 1 year ago #
  2. toomasr

    CoreRebel
    Posts: 482

    See the http://www.zeroturnaround.com/forum/topic.php?id=281 about emptying the ResourceBundle cache.

    Posted 1 year ago #
  3. I looked at it. It is not clear to me how to do it. Do I need to implement a class? If so, do I need to call a method on that class? If so, it does not sound simple to me... Javarebel, please, provide your expertise answer on this one.

    Thanks,

    Rubens.

    Posted 1 year ago #
  4. lauri

    Member
    Posts: 482

    You would need to call that code after you modify resource.properties and before ResourceBundle.getBundle() is called to get the changed resourcebundle. How and when exactly you call it is left for you to decide. If you feel that it is too complicated or too much of a hassle, then the good news is that we have started implementing it inside javarebel. We'll update this thread when it is done.

    Posted 1 year ago #
  5. Here is a Struts 2 action that can be called to reload your Struts 2 resource properties. In the case below, my resource properties are "/classes/struts/resources.properties" and "/classes/struts/resources_pt.properties". Therefore, the resources bundle name is "struts/resources". I make changes to my resources properties file, and then I call the following action, and the resources are dynamically reloaded.

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
    <struts>
    <package name="struts-admin" extends="webapp-struts-default" namespace="/admin">
    <action name="reloadResources" class="com.softlagos.web.struts2.admin.ReloadResourceBundleAction">
    <result type="dispatcher" name="success">/jsp/admin/reloadResources.jsp</result>
    </action>
    </struts>

    /*
    * @(#) $Id: AdminAction.java 989 2008-10-29 17:44:55Z rgomes $
    */
    package com.softlagos.web.struts2.admin;

    import com.opensymphony.xwork2.Action;
    import com.opensymphony.xwork2.ActionSupport;
    import com.opensymphony.xwork2.util.LocalizedTextUtil;

    /**
    * Responsible for reloading the resource bundle
    *
    * @author Rubens Gomes
    */
    public final class ReloadResourceBundleAction extends ActionSupport
    {
    private static final long serialVersionUID = 1;

    /**
    * no-arg default constructor.
    */
    public ReloadResourceBundleAction()
    {
    super();
    }

    /**
    * Called to reload the resource bundle.
    *
    * @return struts result - see struts xml configuration file
    */
    @Override
    public String execute()
    {

    LocalizedTextUtil.clearDefaultResourceBundles();

    LocalizedTextUtil.addDefaultResourceBundle("struts/resources");

    LocalizedTextUtil.setReloadBundles(true);

    return Action.SUCCESS;
    }
    }

    Posted 1 year ago #
  6. ahmax

    Member
    Posts: 1

    rubens //
    i have a some question.
    do you know how to reload when i modified struts.xml files.
    i will waiting for your answer.

    thanks

    Posted 1 year ago #
  7. I usually design all my actions and configure struts.xml upfront. And when I need to change the struts.xml files I usually restart the application. As for reloading the resources files, this is what I do:

    1) change the resources files.
    2) do a build from within Eclipse -- have to do this in order to get the changed resources files in the classpath, because I use maven and I keep all my resources in resources directory.
    3) execute the above action, which call the following execute method -- notice small difference from previous.

    /**
    * Called to reload the resource bundle.
    *
    * @return struts result - see struts xml configuration file
    */
    @Override
    public String execute()
    {

    LocalizedTextUtil.reset();

    LocalizedTextUtil.addDefaultResourceBundle("struts/resources");

    LocalizedTextUtil.setReloadBundles(true);

    return Action.SUCCESS;
    }

    --
    Rubens Gomes
    http://www.rubens-gomes.com

    Posted 1 year ago #
  8. Omni

    guest

    any reason why you did reset() instead of clearDefaultResourceBundles()

    what'll happen if we do both?

    Posted 7 months ago #
  9. Aneesh

    guest

    Use hot deploment. The server need not to restarted.

    Posted 4 weeks ago #

RSS feed for this topic

Reply

(required)

(required)

(optional)

(required)

Allowed markup: a blockquote code em strong ul ol li.
Put code in between `backticks`.

Olark Livehelp