简体   繁体   中英

How do I exclude x.class from being compiled into my jar file?

I'm trying to make POM.xml generate two jar files. One with all the classes, the other excluding one of the classes.

The file i'm trying to exclude is named 'ExcludeMe1.java.'I'm new but it's not my FIRST rodeo, in the code below I've excluded ExcludeMe1.class. But the size of the jar file remains unchanged, and I believe it to still contain the class of which I am excluding. Here's what I mean...

    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
            <execution>
              <id>make-assembly</id>
              <phase>package</phase>
              <goals>
                <goal>single</goal>
              </goals>
              <configuration>
                  <appendAssemblyId>false</appendAssemblyId>
                  <archive>
                    <manifest>
                      <mainClass>com.costanzo.mavendemo.MavenDemo1</mainClass>
                    </manifest>
                  </archive>
                  <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                  </descriptorRefs>
                </configuration>
            </execution>
            <execution>
              <id>make-assembly22</id>
              <phase>package</phase>
              <goals>
                <goal>single</goal>
              </goals>
              <configuration>
                  <excludes>
                      <exclude>${project.basedir}/target/excludeMe/ExcludeMe1.class</exclude>
                  </excludes>
                  <archive>
                    <manifest>
                      <mainClass>com.costanzo.mavendemo.MavenDemo1</mainClass>
                    </manifest>
                  </archive>
                  <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                  </descriptorRefs>
                </configuration>
            </execution>
          </executions>
      </plugin>
    </plugins>

What I expect to be happening is the exclusion of the class file, which size is 1KB. So instead of getting both jar's as size NI expect N, and N-1.

I am still really new to Maven, so hopefully yall can understand. Always ask questions if you need I'll be checking this thing frequently as it is a high priority project.

Excluding a single class using maven to my knowledge is not possible . Exclusion of jars is possible.

您只能从构建过程中排除jar文件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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