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.
Hi Rommain, the sample configuration looks like <
should be better now, thanks for the report
Your welcome. Thanks to you
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?
Hi, are you sure netbeans compiles in target/classes?
to give a try just run mvn compile
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.
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?
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
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
Did you add the pluginRepository https://repository.apache.org/content/groups/snapshots/ ?
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
well to use the snapshots just add a repository on apache snapshot repo and the same for pluginRepository https://repository.apache.org/content/groups/snapshots
Note: maybe you’ll need to clean a bit your local repo depending on your environment
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
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
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
https://repository.apache.org/content/groups/snapshots/org/apache/openejb/maven/tomee-maven-plugin/1.0.1-SNAPSHOT/ here it is
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
your logs say you don’t have the plugin repository (that’s nto but )
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>
</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>
yep but you don’t have
apache-repo-snapshot
Apache Maven Repository
https://repository.apache.org/content/groups/snapshots
?? I show you my pom content and there is:
<repositories>
<repository>
<id>apache-repo-snapshot</id>
<name>Apache Maven Repository</name>
<url>https://repository.apache.org/content/groups/snapshots</url>
</repository>
</repositories>
What do you mean with: you dont have it ??
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
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>
</repository>
</repositories>
I guess this is the : apache snapshot repo, how do i the pluginRepository
add
<pluginRepositories>
<pluginRepository>
<id>…</id>
<url>…</url>
</pluginRepository>
</pluginRepositories>
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?
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 ;))
Do you startup tommee with clean package tomee:run how do you stop it? clean package tomee:stop???????????????
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?
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!!!
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”
If i use tomee:start the updated class will work too?
Im getting: java.lang.OutOfMemoryError: PermGen space when i do a third change with this is impossible to use this.
would need more info on why to help, maybe send a mail on openejb user mailing list with detail son your case
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.
normally it matches the last one but you should be able to speicify it through the tomeeVersion attribute (from memory)
What do you mean with: “from memory” ?? Is the tomeeVersion is an attribute for the plugin configuration?
yep http://openejb.apache.org/tomee-maven-plugin.html
I see, thanks, i will check it.
the page you gave me (http://openejb.apache.org/documentation.html) is not like a link in http://openejb.apache.org/documentation.html.
right i think we need to refactor a bit our doc but personally i don’t have enough time :s
any help is appreciated ;), pages are here http://svn.apache.org/repos/asf/openejb/site/trunk/content/
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
hmm the xml is not wel lprinted, send a mail to openejb mailing list with your config (and maybe a sample project)
This post is truly a fastidious one it assists new the web viewers, who are wishing in favor of blogging.
Hello to all, the contents present at this web site are truly
remarkable for people experience, well, keep up the good work fellows.
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.
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 😉
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.
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
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)