Search code examples
javamavenjar

Maven only include some classes


I have multiple classes in my project, but for a specific jar I don't want to put all classes into the jar.

    <profile>
        <id>test</id>
        <build>
            <finalName>THRechner-test</finalName>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>3.2.2</version>
                    <configuration>
                        <includes>
                            <include>my.koque.threchner.Einheiten</include>
                        </includes>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>

Then I run the following command: mvn clean package -Ptest, but the class is not put into the jar. Running the command without the include lines does put all files into the jar.

How can I just include one class into the jar?


Solution

  • You must configure the jar plugin like this :

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <includes>                      
                        <include>**/Einheiten.class</include>
                    </includes>
                </configuration>
            </plugin>