简体   繁体   English

如何在pom.xml文件中将war文件添加为maven依赖项

[英]How to add a war file as a maven dependency in pom.xml file

I have a project with 2 packages in it. 我有一个包含2个软件包的项目。 I have a war file present in 1st package. 我在第一个包裹中有一个战争档案。 I want to make use of this war file in package 2. How can I add maven dependency in package 2 pom.xml file. 我想使用软件包2中的war文件。如何在软件包2 pom.xml文件中添加maven依赖项。

In general war package usually don't make sense to use them as dependencies. 通常, war包通常没有意义将它们用作依赖项。 But you can create separate jar packages of the classes (incl. resources) which are in the war project. 但是您可以为war项目中的类(包括资源)创建单独的jar包。 This can be achieved by using the following in your 1st package: 这可以通过在第一个软件包中使用以下命令来实现:

<project>
  <packaging>war</packaging>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          <attachClasses>true</attachClasses>
        </configuration>
      </plugin>
    </plugins>
  </build>
  ...
</project>

So this create a supplemental jar file with the following coordinates groupId:artifactId:classifier:version in this case groupId:artifactId:classes:version which you now can use as a dependency in your 2nd project. 因此,这将创建一个具有以下坐标groupId:artifactId:classifier:version的补充jar文件,在本例中为groupId:artifactId:classes:version ,您现在可以将其用作第二项目中的依赖项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM