Maven 2.2.1:[警告] JAR 将为空 - 没有内容被标记为包含 [英] Maven 2.2.1: [Warning] JAR will be empty - no content was marked for inclusion

查看:117
本文介绍了Maven 2.2.1:[警告] JAR 将为空 - 没有内容被标记为包含的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Maven 2.2.1JDK - 1.6.0_45

Maven 2.2.1 JDK - 1.6.0_45

[警告] JAR 将为空 - 没有内容被标记为包含!构建成功

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

但是构建使用 pom.xml 但没有类文件创建 jar.

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

在 maven 源代码中,只有在找不到源目录时才会抛出此异常.

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

该版本适用于所有其他开发人员,除了我的工作站和另外一台工作站

我已经尝试了针对堆栈溢出问题提供的所有解决方案.

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

我的源目录是 src/java.我还创建了 src/main/java 作为源仍然没有结果.我打电话给 mvn -o jar:jar &&调用 mvn -o antrun:run-o 是因为此时我正在用一些旧罐子进行测试.

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>

推荐答案

首先按照Maven 中的约定,这意味着您的生产源代码应该在 src/main/java 中.您还应该将案例中的资源(如属性文件或其他类型的文件(如 xml 文件))定位到适当的位置,该位置用于生产 src/main/resources 和单元测试 src/测试/资源.

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.

您应该更改的第一件事是迁移过程中项目的目录结构.这将在 Maven 中省去许多配置方面的麻烦,因为您违反了 convention over configuration 范式.

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.

您在 src/test/java 中的单元测试代码并遵循 单元测试的命名约定 这意味着将您的单元测试命名为 *Test.java 仅此而已.您不需要定义一个套件来运行所有测试.如果您遵循命名约定 maven-surefire-plugin 将为您完成所有工作.

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.

从你的 pom 配置中删除 antrun 插件并使用

Remove the antrun plugin from your pom configuration and use

mvn install

而是将您生成的 jar 安装到本地存储库中.基于 构建生命周期,您将编译,单元测试您的代码并将其打包到生成的 jar 文件中.

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.

通常在 Maven 中没有理由单独调用 mvn jar:jar.

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

除此之外你应该停止使用 Maven 2.2.1 因为它已经定义了生命终结.最好从 Maven 3.X 开始.但是我之前写的所有内容都是有效的 Maven 3.

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.

这篇关于Maven 2.2.1:[警告] JAR 将为空 - 没有内容被标记为包含的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆