2013-05-29 55 views
0

今天我配置的Maven插件战争这样的:如何用类路径资源配置Maven插件?

<groupId>org.apache.maven.plugins</groupId> 
<artifactId>maven-war-plugin</artifactId> 
<configuration> 
    <webXml>${basedir}/../common/WEB-INF/web.xml</webXml> 
</configuration> 

这让我分享几个项目之间的web.xml文件。 这种方法的问题是我的Maven项目不是自包含的。它取决于文件系统上的相对路径。

是否有可能做到这样的事情? :

<webXml>classpath:com/mycompany/common/web.xml</webXml> 

当然,使该文件在插件的类路径中可用。

由于

+0

你可以使用绝对路径,如 “d:\ dev的” –

+0

尝试下构建添加文件位置/资源 \t \t \t \t \t \t \t \t \t ... \t \t \t Lavanya

回答

1

第一步是创建与含有web.xml包装类型jar专用Maven的模块。我们称之为com.mycompany:common。

是否有可能做到这样的事情? :

<webXml>classpath:com/mycompany/common/web.xml</webXml> 

你试过即你肯定知道这是行不通的?如果是这样,我想你必须使用领先的'/'(/ com/...)。

当然,使该文件在 插件的类路径中可用。

那很简单,然后......只需添加一个依赖到com.mycompany:common以使其在类路径中可用。当然,它必须在你的Maven仓库中可用。

如果classpath:不工作,我真的不知道我自己了,你可以使用maven-dependency-plugin从JAR解压web.xml,以使其可在maven-war-plugin

的pom.xml

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-dependency-plugin</artifactId> 
    <executions> 
    <execution> 
     <id>unpack-web-xml</id> 
     <phase>..any phase before packaging..</phase> 
     <goals> 
     <goal>unpack</goal> 
     </goals> 
     <configuration> 
     <artifactItems> 
      <artifactItem> 
      <groupId>com.mycompany</groupId> 
      <artifactId>common</artifactId> 
      <version>1.0</version> 
      <outputDirectory>...dir you'll use for the war plugin later...</outputDirectory> 
      <includes>/com/mycompany/common/web.xml</includes> 
      </artifactItem> 
     </artifactItems> 
     </configuration> 
    </execution> 
    </executions> 
</plugin> 
+0

谢谢,我可以使用依赖插件。注意:类路径:不起作用(至少对于战争插件),它试图在文件系统上找到它。 – PeeWee2201