0

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...

1 Answers1

1
  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.

Community
  • 1
  • 1
Laurentiu
  • 74
  • 2
  • Thank you very much... I'm having a problem when try to startup the WebApp... I'm getting this error: – Cristián Munizaga Sep 01 '14 at 16:52
  • 2014-08-29 16:29:04.736::WARN: Failed startup of context org.mortbay.jetty.plugin .Jetty6PluginWebAppContext@1cb817b{/MyApp,Path\MyApp\src\main\webapp} org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 2 in XML document from URL [jar:file:/C:/repositoryMaven/MyAppModelApp/0.1.0. BUILD-SNAPSHOT/MyAppModelApp-0.1.0.BUILD-SNAPSHOT-jar-with-dependencies.jar!/META-INF/spring/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 919; cvc-elt.1: Cannot find the declaration of element 'beans'. at org.springf... – Cristián Munizaga Sep 01 '14 at 16:53
  • This happens when the webapp (WAR) try to read the applicationContext.xml of the JAR... – Cristián Munizaga Sep 01 '14 at 16:54
  • Do you have an error in the applicationContext.xml file in jar-module? Or maybe you do not have all the dependencies needed in jar-module – Laurentiu Sep 01 '14 at 17:01
  • right click on jar-module > Run As > Maven Build... and set the goals to clean and install. If it fails then it's just because of jar-module – Laurentiu Sep 01 '14 at 17:03