TomEE maven plugin: reload your app automatically!


TomEE maven plugin is pretty powerful since it can deploy the application of the current pom, deploy other applications, add librairies to the container, create a zip of the server and attach it to the build etc…but in development reloading of application is pretty nice.

This feature was added this week on trunk.

Here how to use it.

First the tomee-maven-plugin allows to observe file system to synchronize it with the deployed application.

To do it simply add a synchronization block. This block accepts the following configuration:

  • resourcesDir (default src/main/webapp): where to take resources
  • binariesDir (default target/classes): where to take binaries
  • targetBinariesDir (default your-webapp/WEB-INF/classes): where to put binaries
  • targetResourcesDir (default your-webapp/): where to put resources
  • updateInterval (default 5s)
  • extensions (default: .html, .css, .js, .xhtml)
  • regex (default null, if not null used to match files to synchronize)

Then a new parameter was added: reloadOnUpdate (a boolean for now).

The idea is to set this boolean to true and to add to extensions .class. Doing it, the tomee maven plugin will synchronize all compiled sources of the project and then reload (undeploy/deploy) the application.

With such a configuration you can pretty quickly use F5 after a source update to see the updates without stopping/starting TomEE.

Note: think to force the compiler to push new compiled sources in target/classes (or use mvn compile ;)).

Here a sample configuration:

<plugin>
  <groupId>org.apache.openejb.maven</groupId>
  <artifactId>tomee-maven-plugin</artifactId>
  <version>1.0.1-SNAPSHOT</version>
  <configuration>
    <synchronization>
      <extensions>
        <extension>.class</extension>
      </extensions>
    </synchronization>
    <reloadOnUpdate>true</reloadOnUpdate>
  </configuration>
</plugin>

Note: this feature needs a reloadable context (webapp). It is automatically taken into account since TomEE 1.5.2 but for previous versions (1.5.1 at least) you can need to activate it in server.xml.

Advertisements

49 thoughts on “TomEE maven plugin: reload your app automatically!

  1. JL Cetina

    I copy and paste the sample configuration, but nothing happen, im using netbeans 7.2 with TomEE 1.5, do i missing something? i just copy/paste the sample config and then restart my TomEE, then when my app deploy y change a String but the change is not reflecting, when i change the String i use the goal: maven compile, but nothing, my app is a jsf app (myfaces).

    Do i miss something?

    Reply
      1. JL Cetina

        I erase the target/classes directory, then i execute maven compile and i observe the directory was created again, then i resume that of course it use the target/classes directory.

      2. JL Cetina

        I delete the generated clases in my_project/target/classes/com.mypackage/MyClass.class then i use mvn compile and i see the MyClass.class file was created again, with this im sure that netbeans save the classes in the target/classes directory.

        What it can be?

      3. rmannibucau Post author

        well can you try the following please?

        1) cd …/mywar
        2) mvn clean package tomee:run
        3) edit any src/main/java/**/*.java
        4) in another console but in same folder: mvn compile
        5) wait a bit you should see something like:

        [INFO] [Updating] /tmp/tmp-reload/target/classes/org/superbiz/Foo.class to /tmp/tmp-reload/target/apache-tomee/webapps/tmp-reload-1.0/WEB-INF/classes/org/superbiz/Foo.class
        [INFO] Reloading /tmp/tmp-reload/target/apache-tomee/webapps/tmp-reload-1.0

      4. JL Cetina

        When i run mvn clean package tomee:run i always get this:

        No plugin found for prefix ‘tomee’ in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/root/.m2/repository), central (http://repo.maven.apache.org/maven2)%5D

    1. JL Cetina

      When i do a maven clean with netbeans i get this:

      The POM for org.apache.openejb.maven:tomee-maven-plugin:jar:1.0.1-SNAPSHOT is missing, no dependency information available
      Failed to retrieve plugin descriptor for org.apache.openejb.maven:tomee-maven-plugin:1.0.1-SNAPSHOT: Plugin org.apache.openejb.maven:tomee-maven-plugin:1.0.1-SNAPSHOT or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.openejb.maven:tomee-maven-plugin:jar:1.0.1-SNAPSHOT

      Here is the plugin in my pom.xml:

      org.apache.openejb.maven
      tomee-maven-plugin
      1.0.1-SNAPSHOT

      .class

      true

      Reply
      1. JL Cetina

        I add this repository to my pom:

        -repository-
        -id- apache-repo-snapshot-id-
        -name- Apache Maven Repository -/name-
        -url-https://repository.apache.org/content/groups/snapshots -url-
        -/repository-

        I have the same problem

      2. rmannibucau Post author

        well if you have the pluginRepository too it should be fine

        probably means your local repo is corrupted

        try to remove ~/.m2/repository/org/apache/openejb/maven

      3. JL Cetina

        Is the version in your example is ok??

        you have: 1.0.1-SNAPSHOT and i can see that only exists: 1.0.0 and 1.0-alpha-1

      4. JL Cetina

        I deleted, but the same:

        mvn clean package tomee:run
        [INFO] Scanning for projects…
        [WARNING] The POM for org.apache.openejb.maven:tomee-maven-plugin:jar:1.0.1-SNAPSHOT is missing, no dependency information available
        [WARNING] Failed to retrieve plugin descriptor for org.apache.openejb.maven:tomee-maven-plugin:1.0.1-SNAPSHOT: Plugin org.apache.openejb.maven:tomee-maven-plugin:1.0.1-SNAPSHOT or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.openejb.maven:tomee-maven-plugin:jar:1.0.1-SNAPSHOT
        Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml
        Downloading: http://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml
        Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml (21 KB at 4.5 KB/sec)
        Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml (11 KB at 2.3 KB/sec)
        [INFO] ————————————————————————
        [INFO] BUILD FAILURE
        [INFO] ————————————————————————
        [INFO] Total time: 5.516s
        [INFO] Finished at: Wed Oct 17 17:12:01 CDT 2012
        [INFO] Final Memory: 8M/109M
        [INFO] ————————————————————————
        [ERROR] No plugin found for prefix ‘tomee’ in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/root/.m2/repository), central (http://repo.maven.apache.org/maven2)%5D -> [Help 1]
        [ERROR]
        [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
        [ERROR] Re-run Maven using the -X switch to enable full debug logging.
        [ERROR]
        [ERROR] For more information about the errors and possible solutions, please read the following articles:
        [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundForPrefixException

  2. JL Cetina

    I have this in my pom.xml

    <repositories>
    <repository>
    <id>apache-repo-snapshot</id>
    <name>Apache Maven Repository</name>
    <url>https://repository.apache.org/content/groups/snapshots</url&gt;
    </repository>
    </repositories>

    <plugin>
    <groupId>org.apache.openejb.maven</groupId>
    <artifactId>tomee-maven-plugin</artifactId>
    <version>1.0.1-SNAPSHOT</version>
    <configuration>
    <synchronization>
    <extensions>
    <extension>.class</extension>
    </extensions>
    </synchronization>
    <reloadOnUpdate>true</reloadOnUpdate>
    </configuration>
    </plugin>

    Reply
      1. rmannibucau Post author

        Please read carefully what i wrote i DON’T speak of repository tag

        ok ok, wordpress swallows my tags

        in fact i was speaking about pluginRepository tag

  3. JL Cetina

    Sorry Rommain, but i dont undertand this: “well to use the snapshots just add a repository on apache snapshot repo and the same for pluginRepository https://repository.apache.org/content/groups/snapshot

    I have in the pom repository this:

    <repositories>
    <repository>
    <id>apache-repo-snapshot</id>
    <name>Apache Maven Repository</name>
    <url>https://repository.apache.org/content/groups/snapshots</url&gt;
    </repository>
    </repositories>

    I guess this is the : apache snapshot repo, how do i the pluginRepository

    Reply
      1. JL Cetina

        Done, but i have a question, when i use mvn clean i see the app is deployed somewhere!! i see a new apache-tomee folder under target, i guess this is created by the plugin, if i edit some java class and then compile with mvn the log says updating…….. but when i go to http://localhost:8080/ i cant see anything, other problem if the plugin works like that (creating the apache tomee folder) how do i add my jars that i normally drop in lib? do i have to drop them again for every clean?, is there a way to use the plugin with the same tomee that i use in my netbeans ide?

      2. rmannibucau Post author

        you run mvn clean compile or mvn compile?

        the idea is to just update so mvn compile would keep everything in place. If you need to add a jar either you configure the synchronization to sync the lib folder or you restart (personally i restart since when i add a lib i change my app enough to justify a stop-work-start flow ;))

      3. JL Cetina

        Do you startup tommee with clean package tomee:run how do you stop it? clean package tomee:stop???????????????

  4. JL Cetina

    I use first: clean package tomee:run but i get errors because i need some jar’s in tome lib folder, for my app.

    is there a way to use the plugin with the same tomee that i use in my netbeans ide?

    Reply
  5. JL Cetina

    Sorry i was mixing maven “instructions”.

    Now i know how can i do it.

    1) mvn clean package
    2) drop my jars under lib folder
    3) mvn tomee:run (when i want to run)
    4) mvn tomee:stop (when i want to stop)

    This works, great.

    Thanks for your patience.

    All its working now!!!

    Reply
    1. rmannibucau Post author

      just a side note: mvn tomee:run is intended to be used with Ctrl+C. The start command (tomee:start) is the one to use if you use stop (otherwise you’ll get an exception i think, not blocking but just to explain). The only difference is run is blocking where start “starts and forgets”

      Reply
      1. JL Cetina

        Im getting: java.lang.OutOfMemoryError: PermGen space when i do a third change with this is impossible to use this.

  6. JL Cetina

    I am suscriber to openejb mailing list, and you fixed some issues to this specific problem, i now this is “resolved” on trunk, but i dont know what version of tomee is using the maven tomee plugin.

    Reply
      1. JL Cetina

        What do you mean with: “from memory” ?? Is the tomeeVersion is an attribute for the plugin configuration?

  7. Markus

    Hi,

    I am using the plugin as follows:

    org.apache.openejb.maven
    tomee-maven-plugin
    1.0.1

    .class
    .tml

    true
    1.5.1
    plus
    false
    5005
    ${project.basedir}/conf

    mysql:mysql-connector-java:5.1.21

    After updating a class the output says: reloading…
    But the change of the class is not deployed.
    Maybe you can give me a hint ?

    Thanks

    Reply
  8. Penny

    Hello to all, the contents present at this web site are truly
    remarkable for people experience, well, keep up the good work fellows.

    Reply
  9. Isabell

    I for one think this was a marvelous post. There might have
    been a couple of more details, yeah, but what was said was said amazingly
    and I could not agree more. Any further posts on this
    topic upcoming? I really hope so. I will bookmark just in case.

    Reply
    1. rmannibucau Post author

      Hi, thanks for the feedback.

      there are already some further post IIRC and no more are scheduled but depending on needs it can still happen 😉

      Reply
  10. Georgetta

    I have already been instructing a class and now we are looking
    at this subject matter in the next week. I will be
    leading my student to look at your post permanently info I have
    already been that means to write something such as
    this in my internet site plus you’ve got offered me a concept.

    Reply
  11. Dhana kumar Anem

    I have the following and I couldn’t see the changes reloaded when xhtml,css,js files are changed.

    Also, how to avoid outOfMemory when multiple times reloaded.

    org.apache.openejb.maven
    tomee-maven-plugin
    1.5.2

    1.5.2
    plus

    .class

    true

    Reply
    1. rmannibucau Post author

      Hi,

      it should be far better on trunk regarding OOME. About the reloading i fear the 1.5.2 i speak about in this article is the current trunk since 1.5.2 was just a bug fix which didn’t get all the features of the 1.6.0-SNAPSHOT. So basically i ythink you need to force your context to be reloadable (or simply use the snapshot if you can)

      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 )

Google+ photo

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

Connecting to %s