How to import/embed one Spring-Maven JAR Application into Another Spring-Maven WAR Application

I want to create the persistence-tier (the Model of MVC) in a different application generating a JAR that will be imported in to the WAR (With the View and Controller of MVC)...

In both aplications (the JAR and the WAR) I want to use Spring (to manage persistence and transactions and dependency injection) and Maven (to manage de dependencies of both projects)...

I think that every Spring-Maven Application would have their own applicationContext.xml (or the WAR Application could inject dependency in the JAR Application too with only one configuration file for both projects?) and I know that each one will have their own pom.xml...

But how must proceed to integrate them? I wish that the JAR Application will be declared as dependency in the WAR Application and that Maven download the Jar automatically from the SVN respository... but I guess that this another question...

Upvotes: 0

Views: 1127

Answers (1)

Laurentiu
Laurentiu

Reputation: 74

  1. Create a simple Maven project (this will be the parent, parent-module) and in pom.xml define the common dependencies for the war-module and jar-module.
  2. Create a new maven module, war-module, and define it as a war and a child of the parent-module. You will have here the web.xml and one applicationContext.xml.
  3. Create a new maven module, jar-module, and define it as a jar and a child of the parent-module. You will have here another applicationContext.xml.
  4. In the pom.xml file from war-module import jar-module as a dependency.
  5. In the applicationContext.xml from war-module import applicationContext.xml from jar-module like here

Hope it helps.

Upvotes: 1

Related Questions