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