【问题标题】:How to exclude a set of packages from maven build jar?如何从 maven build jar 中排除一组包?
【发布时间】:2012-04-02 22:39:15
【问题描述】:

这就是我所需要的。其他详细信息:我有一个 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 仍然包含引导类。我正在用this answer 编译引导类。

在没有引导类的情况下生成 myproject.jar 的任何灯?

【问题讨论】:

    标签: java maven maven-2


    【解决方案1】:

    您必须使用“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>
    

    【讨论】:

    • 你能告诉我你用什么命令来运行特定的执行ID。
    • 谢谢!必须指定default-jar 有什么关系? maven-jar-plugin 会找吗?
    【解决方案2】:

    我认为您可以先看看这个,然后再决定从一个 pom 生成两个 jar。

    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>
    

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-11-22
        • 2011-01-27
        • 1970-01-01
        • 2014-10-29
        • 1970-01-01
        相关资源
        最近更新 更多