0

I have few maven projects while using Eclipse Neon,

I need to run different goals on different projects to be execute as a sequence/

I found an answer that I can't, or an answer for same goal

Example of usage: call clean install of project A and B, clean install -X on project C and then clean install tomcat7:run-war -X on project D

Ori Marko
  • 56,308
  • 23
  • 131
  • 233

2 Answers2

1

If you install a command line Maven, you can call mvn clean install from your shell or cmd. Then you can write a sh or bat file that navigates into the right folders and calls the mvn command.

If you generally want to build all the projects, think about multi-module projects. If this is too much refactoring, you can also define a separate project (as reactor project) that includes your four projects as modules. Running mvn clean install on the whole project would then run the command on all the including modules. In the multi-module setting, it is unfortunately not possible to run diffferent Maven goals for the different modules (https://stackoverflow.com/a/4112696/927493). You either need to call Maven twice (with a different list of modules) or add the tomcat goal to your install phase in the relevant module.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
  • what about `tomcat7:run-war`? – Ori Marko Aug 09 '18 at 14:41
  • `mvn clean install tomcat7:run-war` – jhamon Aug 09 '18 at 14:41
  • Have a look at the Maven documentation about plugins: https://maven.apache.org/guides/mini/guide-configuring-plugins.html – jhamon Aug 09 '18 at 14:46
  • @jhamon I didn't find something relevant, can you give an answer describing your solution? – Ori Marko Aug 09 '18 at 14:50
  • On the first link you have an example on how to run a custom goal (more info on mavan comand can be found there). You can find the complete goals for tomcat7 here: http://tomcat.apache.org/maven-plugin-2.1/tomcat7-maven-plugin/plugin-info.html – jhamon Aug 09 '18 at 14:54
  • @jhamon I'm executing maven goals, but I want to execute different goals on different projects in 1 call of maven, e.g. `clean` project A and `install` on project B – Ori Marko Aug 09 '18 at 14:55
  • @user7294900 AFAIK you cannot include different projects in one maven call. – J Fabian Meier Aug 09 '18 at 14:57
  • @JFMeier as you suggested, it's possible in `multi-module project` – Ori Marko Aug 09 '18 at 14:59
  • You can run Maven goals (and phases) on all modules (or a subset), but with one Maven run, you can only run _the same_ set of goals/phases, e.g. you can run `clean install` on all modules, but for running the tomcat goal, you need a separate Maven call. – J Fabian Meier Aug 09 '18 at 15:05
1

One way to do that is to run maven using command line.

Basic format is :

mvn [goal [goal2 [goal3] ...]]

clean and install are standard goals.

tomcat7:run-war is a plugin goal.

You surely have a <plugin> section in the pom.xml setting the property for this goal. You can find all other goals for tomcat7 plugin here: http://tomcat.apache.org/maven-plugin-2.1/tomcat7-maven-plugin/plugin-info.html

You need to get in each of your projects folder and run the command with approriate goals:

cd <project_A_pom_directory>
mvn clean install
cd <project_B_pom_directory>
mvn clean install -X
cd <project_C_pom_directory>
mvn clean install tomcat7:run-war -X
jhamon
  • 3,603
  • 4
  • 26
  • 37
  • Thank you for your time and answer, can you refer to why it can't be executed in eclipse? Is it a known issue of plugin? Is there an open enhancement? – Ori Marko Aug 09 '18 at 15:10
  • It can be executed in eclipse on a single project: you can set the goals in the `Run Configuration` panel. But you can't run multiple maven builds in sequence with different goals in eclipse – jhamon Aug 09 '18 at 15:13