TomEE Maven Plugin: finer configuration for updates


TomEE maven plugin offers you a way to update file from your maven project to the deployed application. It offers a way to reload the deployed application if a file is updated in the configured update interval. That’s fine but on real projects you want to reload it only if it is a class and not a simple resource (css, js…).

That’s why some more features were added for next version (1.5.2).

Before you were defining:

<configuration>
  <reloadOnUpdate>true</reloadOnUpdate>
  <synchronization>
    <extensions>
      <extension>.class<extension>
      <extension>.html<extension>
      <extension>.js<extension>
      <extension>.jcss<extension>
    </extensions>
  </synchronization>
</configuration>

This is fine but here updating a js, css or html you’ll restart the application.

To avoid it you can now use updateOnlyExtensions block:

</configuration>
  <reloadOnUpdate>true</reloadOnUpdate>
  <synchronization>
    <extensions> <!-- extensions triggering a redeployment -->
      <extension>.class<extension>
    </extensions>
    <updateOnlyExtensions>
      <updateOnlyExtension>.html<updateOnlyExtension>
      <updateOnlyExtension>.js<updateOnlyExtension>
      <updateOnlyExtension>.jcss<updateOnlyExtension>
    </updateOnlyExtensions>
  </synchronization>
</configuration>

This way if you update your binaries the application will be restarted to let you test your app and if you update simply a resource you’ll not need to redeploy the application. It can be nice for frameworks having their own reloading mecanism (JSF, tapestry, …).

Such a configuration is fine for war (sources = src/main/webapp and target/classes) but for ear that’s a bit more complicated. You can of course update a jar but then you loose the udpate of the war etc:

<synchronization>
  <extensions> <!-- extensions triggering a redeployment -->
    <extension>.jar<extension>
  </extensions>
  <binariesDir>${project.basedir}/../someejb/target/</binariesDir>
  <targetBinariesDir>${project.basedir}/target/apache-tomee/apps/myear/</targetBinariesDir>
</synchronization>

Note: adapting paths this hack can be used for jar type projects

That’s why you can now add a block with a list of synchronization (the old one can still be used for compatibility reasons and wars where it is more adapted):

<configuration>
  <synchronizations>
    <synchronization>
      <extensions>
        <extension>.jar<extension>
      </extensions>
      <binariesDir>${project.basedir}/../someejb/target/</binariesDir>
      <targetBinariesDir>${project.basedir}/target/apache-tomee/apps/myear/</targetBinariesDir>
    </synchronization>
    <synchronization>
      <extensions>
        <extension>.class<extension>
      </extensions>
      <binariesDir>${project.basedir}/../somewar/target/classes/</binariesDir>
      <targetBinariesDir>${project.basedir}/target/apache-tomee/apps/myear/somewar/WEB-INF/classes/</targetBinariesDir>
    </synchronization>
  </synchronizations>
</configuration>

Note: this configuration is designed for ears but works for war too so now you can synchronized multiple sources/targets.

Advertisement

3 thoughts on “TomEE Maven Plugin: finer configuration for updates

  1. maxtorzito

    Dont forget to set Project Stage to Development if you are using JSF with this you can see the changes.

    Regards.

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s