Maven 2.2.1: [Warning] JAR will be empty - no content was marked for inclusion

57k views Asked by At
  • Maven 2.2.1

  • JDK - 1.6.0_45

But build creates jar with pom.xml but no class files.

[WARNING] JAR will be empty - no content was marked for inclusion!

On the maven source code this exception is thrown only when source directory is not found.

The build is working for all other developers except on my workstation and one more workstation

I have tried all the solutions provided for this issue on stack overflow.

My source directory is src/java. I also created src/main/java as source still no result. I am calling mvn -o jar:jar && call mvn -o antrun:run -o is becuase at this point I am testing with some old jars.

<build>
        <sourceDirectory>src/java</sourceDirectory>
        <resources>
            <resource>
                <directory>${basedir}/src/java</directory>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.properties</include>
                </includes>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>${basedir}/src/test/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <debug>true</debug>
                    <optimize>false</optimize>
                    <showDeprecation>true</showDeprecation>
                    <source>1.5</source>
                    <target>1.5 </target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>test*/temp/*.java</exclude>
                        <exclude>test*/support/*.java</exclude>
                        <exclude>test*/debug/*.java</exclude>
                    </excludes>
                    <includes>
                        <include>test*/**/AllTests.java</include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.7</version>
                <executions>
                    <execution>
                        <id>default-cli</id>
                        <phase>install</phase>
                        <configuration>
                            <target>
                                <copy file="${project.build.directory}/${artifactId}-${version}.jar"
                                    todir="${user.home}/.m2/repository/${groupId}/${artifactId}/${version}" />
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
2

There are 2 answers

1
khmarbaise On

First follow the conventions in Maven which means your production sources code should be in src/main/java. You should also locate your resources like property files or other kind of files (like xml files) in your case to the proper location which is for production src/main/resources and for unit tests src/test/resources.

The first thing you should change is the directory structure for your project in the process in migration. That will save many hassles with configurations in Maven cause you are violating the convention over configuration paradigm.

Your unit tests code in src/test/java and follow the naming conventions for unit tests which means name your unit tests like *Test.java nothing more. You don't need to define a suite to run all the tests. If you follow the naming convention maven-surefire-plugin will do all the work for you.

Remove the antrun plugin from your pom configuration and use

mvn install

instead to install your produced jar into local repository. Based on the build life cycle you will compile, unit test and package your code into resulting jar files.

Usually in Maven there is no reason to call mvn jar:jar separately.

Apart from that all you should stop using Maven 2.2.1 cause it has defined End Of Life. Better start with Maven 3.X instead. But everything i wrote before is valid Maven 3.

0
Mustafa SDET On

I got Build Success but same error: JAR will be empty - no content was marked for inclusion. It was a test project and I realized that I had no "main" under "src". As soon as I corrected this, it was fixed. I am adding the wrong and right structure screenshots in the attachments:

  • right structure

1

  • wrong structure - missing main folder

2