如何从maven build jar中排除一组包?

时间:2012-03-17 20:11:24

标签: java maven maven-2

这就是我所需要的。其他细节:我有一个src / bootstrap / java文件夹和常规的src / main / java文件夹。出于显而易见的原因,每个人都需要去一个单独的罐子。我能够使用this

生成一个引导程序jar
  <plugin>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.3.1</version>
    <executions>
      <execution>
        <id>only-bootstrap</id>
        <goals><goal>jar</goal></goals>
        <phase>package</phase>
        <configuration>
          <classifier>bootstrap</classifier>
          <includes>
            <include>sun/**/*</include>
          </includes>
        </configuration>
      </execution>
    </executions>
  </plugin>

但是常规jar仍然包含bootstrap类。我正在使用this answer编译引导类。

生成myproject.jar而没有引导类的任何灯光?

3 个答案:

答案 0 :(得分:18)

你必须使用“default-jar”作为ID:

  <plugin>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.3.1</version>
    <executions>
      <execution>
        <id>only-bootstrap</id>
        <goals><goal>jar</goal></goals>
        <phase>package</phase>
        <configuration>
          <classifier>bootstrap</classifier>
          <includes>
            <include>sun/**/*</include>
          </includes>
        </configuration>
      </execution>
      <execution>
        <id>default-jar</id>
        <phase>package</phase>
        <goals>
          <goal>jar</goal>
        </goals>
        <configuration>
          <excludes>
            <exclude>sun/**/*</exclude>
          </excludes>
        </configuration>
      </execution>
    </executions>
  </plugin>

答案 1 :(得分:2)

我认为在决定从一个pom生成两个罐子之前,你可以看看这个。

Maven best practice for generating multiple jars with different/filtered classes?

如果你仍然决定买两个罐子,你可以用它来做。您必须指定正确的排除。

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

答案 2 :(得分:0)

也许使用ProGuard?这是我用来删除未使用的代码。它seems可以将其添加为Maven插件。