1

I have a Java web project that is built using Maven. The project has some annotated classes to generate some sources at build time using a template (velocity). Everything works well so far, I'm using the generated sources flawless.

Right now I need to use those generated classes in a different project. I'm wondering how can I tell maven to package those sources in an additional jar. I would like to use that generated jar in both my main project and the new one as a new dependency.

Any Ideas?

Thanks!

fakefla
  • 156
  • 2
  • 5

1 Answers1

1

Simplest solution is to create a separate project which contains only the generated parts which will by default create a jar file as usual which gives you simple the possibility to reuse that in different other projects. With the following structure this is simple to solve.

  +-- root (pom.xml)
        +--- generated (pom.xml)
        +--- main (pom.xml)
        +--- other (pom.xml)

In you main project just simply define a dependency to your generated project like

<dependency>
  <groupId>what.ever.group</groupId>
  <artifactId>generated</artifactId>
  <version>${project.verison}</version>
</dependency>

and the same in your other module.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • Thanks for the response. I understand the order of the projects in modules. The matter is that I don't know how to extract my generated sources out of my main project. They are in my generated-sources directory but how can I tell maven to package it in the "generated" project you suggest?(I wouldn't like to copy paste those files) Thanks again! – fakefla Feb 12 '14 at 20:53
  • May be you should take a look at the [templating-maven-plugin](http://mojo.codehaus.org/templating-maven-plugin/). The thing sounds to me like a job for a plugin what you are doing. – khmarbaise Feb 12 '14 at 21:39