13

That's all I need. Additional details: I have a src/bootstrap/java folder and the regular src/main/java folder. Each one needs to go to a separate jar for obvious reasons. I was able to generate a bootstrap jar using this:

  <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>

But the regular jar still includes the bootstrap classes. I am compiling the bootstrap classes with this answer.

Any light to generate a myproject.jar WITHOUT the bootstrap classes?

Community
  • 1
  • 1
chrisapotek
  • 6,007
  • 14
  • 51
  • 85

3 Answers3

19

You gotta use "default-jar" for the 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>
TraderJoeChicago
  • 6,205
  • 8
  • 50
  • 54
3

I think you can take a look at this before deciding to generate two jars from one pom.

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

If you still decide to get two jars, you can probably do it using this. You have to specify the proper exclusions.

<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>
Community
  • 1
  • 1
Chinmoy
  • 1,750
  • 2
  • 21
  • 45
0

Maybe use ProGuard? It's what I use to strip out unused code. It seems that you can add it as a Maven plugin.

Community
  • 1
  • 1
Louis Wasserman
  • 191,574
  • 25
  • 345
  • 413