有人可以帮我配置maven-war-plugin吗?如何使用maven-war-plugin在项目之间共享类,配置文件和Web工件...?
出于安全原因,我希望在两台服务器上为两个不同的用户组运行两个非常类似的Web应用程序,而不是仅针对所有用户组部署一个。 因此,我想在它们之间分享尽可能多的代码。
我打算创建一个也可以单独运行的战争,以便在两个独立的Web项目中进行开发并重用其大部分项目。我想重复使用例如Spring配置文件(applicationContext-XX.xml),jspx,css,...和Java代码。但是我还需要编写一些扩展共享类的Java类。
我想使用spring roo生成的测试项目来试用maven-war-plugin。我已经尝试了几件事情,但我仍然遇到部署问题。
如果我只用战我就不能扩展任何Java类的代码不会编译:
<dependency>
<groupId>com.test.pizzashop</groupId>
<artifactId>PizzaShopCommons_WEB</artifactId>
<scope>compile</scope>
<version>0.1.0.BUILD-SNAPSHOT</version>
<type>war</type>
</dependency>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<overlays>
<overlay>
<groupId>com.test.pizzashop</groupId>
<artifactId>PizzaShopCommons</artifactId>
</overlay>
</overlays>
</configuration>
</plugin>
即使我不扩展任何Java类我的Tomcat(MVN tomcat的:运行)做不能开始,因为它不能正确地找到位于lib文件夹中的jar。
我也尝试使用第二个共享项目,其中只包含Java类和Spring配置文件以及所有依赖项,然后打包为jar。在Tomcat中运行主Web应用程序仍导致出现异常:
org.springframework.beans.factory.BeanDefinitionStoreException:IOException从ServletContext资源解析XML文档[/WEB-INF/spring/webmvc-config.xml];嵌套的异常是FileNotFoundException:无法打开ServletContext资源[/WEB-INF/spring/webmvc-config.xml] 此文件webmvc-config.xml位于它应该在战争中的位置(由maven war插件复制)。
<dependency>
<groupId>com.test.pizzashop</groupId>
<artifactId>PizzaShopCommons_WEB</artifactId>
<scope>compile</scope>
<version>0.1.0.BUILD-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.test.pizzashop</groupId>
<artifactId>PizzaShopCommons_SpringConf_Classes_Dependencies</artifactId>
<scope>compile</scope>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
</dependency>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<overlays>
<overlay>
<groupId>com.test.pizzashop</groupId>
<artifactId>PizzaShopCommons_WEB</artifactId>
<excludes>
<exclude>*.java</exclude>
</excludes>
<excludes>
<exclude>*.jar</exclude>
</excludes>
</overlay>
</overlays>
</configuration>
<!-- <executions> <execution> <phase>generate-resources</phase> </execution> </executions> -->
</plugin>
文件结构中产生的战争看起来是这样的:
+---pizzashop-1.0.0-BUILD-SNAPSHOT
| +---images
| | add.png ...
| +---META-INF
| | | MANIFEST.MF
| | \---maven
| | \---com.test.pizzashop
| | \---PizzaShop
| | pom.properties
| | pom.xml
| +---styles
| | standard.css ...
| \---WEB-INF
| | web.xml
| +---classes
| | | builddef.lst ...
| | +---com
| | | \---test
| | | \---pizzashop
| | | +---domain
| | | | Pizza.class ...
| | | +---service
| | | | PizzaService.class ...
| | | \---web
| | | PizzaController.class ...
| | \---META-INF
| | | aop-ajc.xml
| | | persistence.xml
| | \---spring
| | applicationContext-security.xml
| | applicationContext.xml
| | database.properties
| +---i18n
| | application.properties ...
| +---layouts
| | default.jspx ...
| +---lib
| | antlr-2.7.6.jar ...
| +---spring
| | | root-context.xml
| | | webmvc-config.xml
| | \---appServlet
| | xx_servlet-context_xx.xml
| +---tags
| | | create.tagx ...
| \---views
| | dataAccessFailure.jspx ...
我怎样才能得到这个运行?只有一个共享项目 - 一个罐子还是战争?是否有可能实现这一目标?
2我看到这里的东西:1)做一个多模块maven项目,然后在你的项目之间使用普通的东西。 2)使用maven覆盖来继承和扩展你的spring配置文件http://maven.apache.org/plugins/maven-war-plugin/overlays.html – mfirry 2012-08-07 21:56:59
那么,使用多模块项目是很好的,因为它使建设所有项目更容易,以及使用继承进行中央管理的依赖:[链接](http://maven.apache.org/guides/introduction/introduction-to-the-pom.html)不幸的是,这并没有解决我的任何问题。 – Ninca 2012-08-27 15:45:00