Java Maven:JAR 将为空 - 没有内容被标记为包含

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19606739/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 18:43:53  来源:igfitidea点击:

Maven: JAR will be empty - no content was marked for inclusion

javamavenjar

提问by webguy

I have a minor problem with maven. When I run the command mvn package I get the following warning:

我对 maven 有一个小问题。当我运行命令 mvn package 时,我收到以下警告:

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

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

The build is successful but the produced jar-file is empty as the warning says.

构建成功,但生成的 jar 文件如警告所示为空。

Why is this and what am I doing wrong?

为什么会这样,我做错了什么?

Here is my pom.xml

这是我的 pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
   http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>framework</groupId>
<artifactId>framework</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>framework</name>
<url>http://maven.apache.org</url>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    My dependencies
</dependencies>

<build>
    <directory>target</directory>
    <outputDirectory>target/classes</outputDirectory>
    <finalName>${project.artifactId}-${project.version}</finalName>
    <testOutputDirectory>target/test-classes</testOutputDirectory>
    <sourceDirectory>src</sourceDirectory>
    <scriptSourceDirectory>src</scriptSourceDirectory>
    <testSourceDirectory>src</testSourceDirectory>
    <testResources>
        <testResource>
            <directory>test</directory>
        </testResource>
    </testResources>

    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <includes>
                    <include>src</include>
                </includes>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <outputDirectory>lib</outputDirectory>
            </configuration>
        </plugin>

    </plugins>
</build>

采纳答案by Robert Scholte

I hope you have good reason notto follow the standard directory layout, otherwise consider to rearrange the folders: it will make your life a lot easier (as well as for your co-workers). My guess is that nothing has been compiled. In that case: removing the configuration of the maven-compiler-plugin should be enough.

我希望您有充分的理由遵循标准目录布局,否则请考虑重新排列文件夹:这将使您的生活更轻松(以及您的同事)。我的猜测是什么都没有编译。在这种情况下:删除 maven-compiler-plugin 的配置就足够了。

回答by kinjelom

Please try this one:

请试试这个:

<build>
  <finalName>${project.artifactId}-${project.version}</finalName>
  <sourceDirectory>src</sourceDirectory>
  <testSourceDirectory>test</testSourceDirectory>
  <resources>
    <resource>
      <directory>src</directory>
      <excludes>
        <exclude>**/*.java</exclude>
      </excludes>
    </resource>
  </resources>
  <testResources>
    <testResource>
      <directory>test</directory>
      <excludes>
        <exclude>**/*.java</exclude>
      </excludes>
    </testResource>
  </testResources>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>${maven-compiler-plugin.version}</version>
      <configuration>
        <source>${maven.compiler.source}</source>
        <target>${maven.compiler.target}</target>
      </configuration>
    </plugin>
  </plugins>

</build>

If you want to convert an existing Eclipse Java Projectjust right click on Java Projectand click Configure/Convert to Maven Project.

如果要转换现有的,Eclipse Java Project只需右键单击Java Project并单击Configure/ Convert to Maven Project