How do I exclude java files from a jar in maven-jar-plugin?

Shahar Hamuzim Rajuan

I created a pom.xml to compile my project and package it as a jar, and indeed it comiples and the jar is created - problem is that i got a jar with both classes and java inside, and i only want the classes inside.

How do I lose the java files? I don’t need them.

this is the pom.xml that i created:

<build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <finalName>api-interfaces</finalName>
        <plugins>
        <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <id>make-a-jar</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            <configuration>
          <excludes>
            <exclude>*.properties</exclude>
              <exclude>*.xml</exclude>
               <exclude>sql/**</exclude>
                <exclude>META-INF/**</exclude>
                 <exclude>*.jar</exclude>
                  <exclude>*.java</exclude>
                   <exclude>default-configs/**</exclude>

          </excludes>
          </configuration>
        </plugin>
       </plugins>
    </build>

this is the jar that i get

Silly Freak

Here's the culprit:

    <resources>
        <resource>
            <directory>src/main/java</directory>
            <filtering>true</filtering>
        </resource>
    </resources>

With this, you explicitly specify that files in src/main/java, i.e. the .java files, should be included in the jar.

you can either use the standard maven layout and put resources in src/main/resources, or explicitly exclude .java files using this:

    <resources>
        <resource>
            <directory>src/main/java</directory>
            <filtering>true</filtering>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>
        </resource>
    </resources>

See maven resource plugin for more infos, especially the include/exclude examples

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

maven-dependency-plugin: exclude .jar files

From Dev

How to use maven assembly plugin to exclude a package from dependency jar?

From Dev

Maven assembly or shade plugin - How to exclude sources from jar?

From Dev

I wish to exclude some class files from my jar. I am using maven-assembly-plugin. It still adds the files. I dont get any error

From Dev

How to exclude a package from a jar (with maven)

From Dev

Maven - How to exclude dependencies from generated JAR

From Dev

Maven Create Jar and exclude Files

From Dev

How do I exclude a package from an imported JAR for a project in Eclipse?

From Dev

maven: exclude jar from JDK

From Dev

How do I change a jar version from a Grails Plugin?

From Dev

How can I exclude some packages (within a JAR) from a Maven dependency?

From Dev

How to add files from webapp directory to jar using Maven Assembly plugin?

From Dev

Java - How do I load a .wav from inside the jar?

From Dev

Java - How do I load a .wav from inside the jar?

From Dev

Maven: How can I run/include a class in a jar with the failsafe plugin?

From Dev

maven: how to build the dependency from source.jar to jar files and put the jar file as it dependency?

From Dev

How to activate Java Properties Plugin during the Maven JAR project analysis?

From Dev

I used gradle to build a fat jar with all of my dependencies included in it. Now, when using distZip, how do I exclude these jar files?

From Dev

Sonar Maven Plugin: How do I exclude test source directories?

From Dev

How to stop maven from downloading some jar files from repositorty

From Dev

How to exclude resource files when lein jar?

From Dev

How to generate javadoc from many plugin jar files containing source

From Dev

How to generate javadoc from many plugin jar files containing source

From Dev

How do I open a jar file with java?

From Dev

How to create jar from plugin?

From Dev

maven: how to include annotation-generated .java files in the .jar

From Dev

maven: how to include annotation-generated .java files in the .jar

From Dev

How do I properly include an external jar file for a cordova plugin?

From Dev

How do I prevent maven from appending the version number to the built jar?

Related Related

  1. 1

    maven-dependency-plugin: exclude .jar files

  2. 2

    How to use maven assembly plugin to exclude a package from dependency jar?

  3. 3

    Maven assembly or shade plugin - How to exclude sources from jar?

  4. 4

    I wish to exclude some class files from my jar. I am using maven-assembly-plugin. It still adds the files. I dont get any error

  5. 5

    How to exclude a package from a jar (with maven)

  6. 6

    Maven - How to exclude dependencies from generated JAR

  7. 7

    Maven Create Jar and exclude Files

  8. 8

    How do I exclude a package from an imported JAR for a project in Eclipse?

  9. 9

    maven: exclude jar from JDK

  10. 10

    How do I change a jar version from a Grails Plugin?

  11. 11

    How can I exclude some packages (within a JAR) from a Maven dependency?

  12. 12

    How to add files from webapp directory to jar using Maven Assembly plugin?

  13. 13

    Java - How do I load a .wav from inside the jar?

  14. 14

    Java - How do I load a .wav from inside the jar?

  15. 15

    Maven: How can I run/include a class in a jar with the failsafe plugin?

  16. 16

    maven: how to build the dependency from source.jar to jar files and put the jar file as it dependency?

  17. 17

    How to activate Java Properties Plugin during the Maven JAR project analysis?

  18. 18

    I used gradle to build a fat jar with all of my dependencies included in it. Now, when using distZip, how do I exclude these jar files?

  19. 19

    Sonar Maven Plugin: How do I exclude test source directories?

  20. 20

    How to stop maven from downloading some jar files from repositorty

  21. 21

    How to exclude resource files when lein jar?

  22. 22

    How to generate javadoc from many plugin jar files containing source

  23. 23

    How to generate javadoc from many plugin jar files containing source

  24. 24

    How do I open a jar file with java?

  25. 25

    How to create jar from plugin?

  26. 26

    maven: how to include annotation-generated .java files in the .jar

  27. 27

    maven: how to include annotation-generated .java files in the .jar

  28. 28

    How do I properly include an external jar file for a cordova plugin?

  29. 29

    How do I prevent maven from appending the version number to the built jar?

HotTag

Archive