0

My project consists of maven modules and a parent module. Each module will have its own xml resources. I want to change output directory of each module to parent module's directory. All the resources and class files will go to parent module's output directory. I changed outputdirectory of each submodule to parent module's output directory as the following:

<build>
       <outputDirectory>../target/classes</outputDirectory>
</build>

The problems:

  1. When i clean the parent module using eclipse clean, it doesnt copy the outputs of sub modules to parent's module's output directory because i cant change output folder of submodules to parent module's output folder through eclipse project properties.
  2. When i mvn clean install, it copies the last build sub module's output to target directory because mvn clean is executed for each sub module, and it cleans the previously build module's outputs.
  3. I want to create a single jar for all modules, is that possible?
  4. How can i combine all outputs of parent and sub modules?
Murat
  • 3,084
  • 37
  • 55

1 Answers1

2

Please don't do this, this goes completely against every rule. It wouldn't work either, because modules are handled one after the other.

The reason for using different modules is to clearly separate them. Mixing output folders would sabotage that goal.

  • keep your modules separate
  • create a separate module which collects all your other modules using maven-assembly-plugin or maven-shade-plugin into a single target jar.

And, once again:

Maven projects should never, ever write outside their project's folder!

blackbuild
  • 5,026
  • 1
  • 23
  • 35
  • As you said ,i used maven-assembly-plugin and it seems solved my problem. i collected all modules into a single target jar. This tutorial helped me: http://rombertw.wordpress.com/2010/05/14/maven-recipe-building-an-aggregate-jar/ My problem is that i have resources for the parent and sub modules. When i right click and execute a sub module (run as application) it cant see the resources of parent module. When i collect them into a single jar, i also collect resources and there is no problem in that. But i dont want to execute jar always because it is easier to right click and run as application – Murat Apr 14 '14 at 10:55
  • Your parent project should not have resources. Parent projects are POM projects without content. This could explain your problems. – blackbuild Apr 14 '14 at 11:08
  • I have common resources and i put them into the parent module. How should i solve this issue? – Murat Apr 14 '14 at 11:09
  • 2
    Put your resources into a separate module and have the other modules depend on it. – blackbuild Apr 14 '14 at 12:28