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

2022-09-01 15:50:08

我有一个小问题与maven。当我运行命令mvn包时,我得到以下警告:

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

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

这是为什么,我做错了什么?

这是我的绒球.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>


答案 1

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


答案 2

请尝试这个:

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

如果要转换现有内容,请右键单击并单击 /。Eclipse Java ProjectJava ProjectConfigureConvert to Maven Project


推荐