Maven包资源与类

时间:2014-06-16 17:16:33

标签: java maven resources

我正在使用Maven生成War文件并发布类jar:

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.4</version>
    <configuration>
        <attachClasses>true</attachClasses>
    </configuration>
</plugin>

是否也可以在类jar中发布战争中的资源?

1 个答案:

答案 0 :(得分:1)

我的建议是将这些资源放在他们自己独立的jar模块中,然后让战争将它们用作依赖项。这样,战争和任何其他项目都可以将资源称为任何其他依赖项。

但如果你不想这样做或者你不能这样做,我认为你必须使用classifierAs I said, this isn't ideal. Here's a detailed tutorial on how to do it

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <executions>
          <execution>
            <id>only-library</id>
            <goals><goal>jar</goal></goals>
            <phase>package</phase>
            <configuration>
              <classifier>only-library</classifier>
              <excludes>
                <exclude>**/Main*</exclude>
              </excludes>
            </configuration>
          </execution>
          <execution>
            <id>everything</id>
            <goals><goal>jar</goal></goals>
            <phase>package</phase>
            <configuration>
              <classifier>everything</classifier>
              <includes>
                <include>**/*</include>
              </includes>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>