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

2

25
  • 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>
Latrinalatrine answered 23/6, 2015 at 16:12 Comment(8)
Do you have an entry in the POM file for <packaging>? What happens when you try to run mvn compile?Wyatan
Check your basedir include, it includes only .xml and .properties hence exclude all elseLeoine
@Ryan J : yes it is <packaging>jar</packaging>Latrinalatrine
@Leoine - Those are resources include. I do have the <sourceDirectory tag> I tried adding .java and .class as well it did not work.Latrinalatrine
You should use src/main/resources for resources, and src/main/java for Java... See maven.apache.org/guides/introduction/…Leoine
@RyanJ mvn compile is compiling the files. But now jar is not getting created.Latrinalatrine
@Danielson: That would be ideal. But we can have our own directory structure as well. It is an old project. That was working on maven1. Even the current build process is working for other developers. non standard directory structure can be aslo be used using <sourceDirectory> tag. See maven.apache.org/general.html#dir-structLatrinalatrine
@Latrinalatrine sorry. I tried, but have Lambda functions in all my projects, won't compile to Java 5. Still your company should update to this century's ;-)Leoine
M
20

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.

Millenarianism answered 23/6, 2015 at 18:25 Comment(1)
Thanks @khmarbaise. The suggested upgrade is in progress. In the meantime I am trying to fix a problem which is only reproducible on one or two workstation and working for others.Latrinalatrine
P
1

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

Pachyderm answered 17/8, 2022 at 11:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.