Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Maven, goals order

Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everyone,

I'm experiencing an issue with maven goals order, that are registered to one phase "clean" that belongs to the clean lifecycle. I have a little project on EJB. All the beans (indeed, only one stateless bean there) are to be deployed on TomEE AS. So I use tomee-maven-plugin to stop/start the server, deploy/undeploy the jar module. My pom.xml is as follows:

The goal "tomee:stop" stops the server, the goal "tomee:start" starts the server, the goals "tomee:deploy" and "tomee:undeploy" deploy and undeploy my module respectively.

When I execute

It starts the server and deploys application. I can see the result via this command:

But when I try to stop the server and clean the project (mvn clean) first I obtain the error message:

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building mvn-firstejb-tomee 1.0
[INFO] ------------------------------------------------------------------------
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ mvn-firstejb-tomee ---
[INFO] Deleting D:\Tmp_f\mvn-firstejb-tomee\target
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.720s
[INFO] Finished at: Sun May 31 15:01:37 GMT+03:00 2015
[INFO] Final Memory: 4M/115M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.4.1:clean (default-clean) on project mvn-firstejb-tomee: Failed to clean project: Failed to delete D:\Tmp_f\mvn-firstejb-tomee\target\mvn-firstejb-tomee.jar -> [Help 1]
[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] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1]

There are two goals registered to the clean phase of my project. One goal ("tomee:stop") belongs to tomee-maven-plugin and the other("clean:clean") belongs to maven-clean-plugin. I generated effective pom for my project and got that maven-clean-plugin goes after tomee-maven-plugin, so as I understand, it should be executed after tomee plugin:

But nevertheless, maven-clean-plugin is executed first (see the error message above). But the jar module is locked by the server and cannot be deleted.

As per this link: "The goals that are configured will be added to the goals already bound to the lifecycle from the packaging selected. If more than one goal is bound to a particular phase, the order used is that those from the packaging are executed first, followed by those configured in the POM."

So the goal "clean:clean" is already bound to the clean phase of the clean lifecycle by jar packaging specification. That is why it is executed first.

Could someone please suggest whether it is possible to run goals, specified in the pom.xml before the goals that are assumed by packaging as defaults and what is the workaround for my issue?
Posts: 2759
Eclipse IDE Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, and trying to control the order of goals lies the way of madness. You can bind a goal to the pre-clean phase to execute goals before clean.

Generally, a build execution should be self contained too. It's not a good idea to keep your web server running after your build has finished execution. If you r build has started a web server, it should stop it. One execution shouldn't be performing cleanup for other executions. You are going to make your life very difficult if you do this.
    Bookmark Topic Watch Topic
  • New Topic