25

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

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

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

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

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

4

2 回答 2

33

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

于 2013-10-26T12:40:48.293 回答
1

请试试这个:

<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 Project,只需右键单击Java Project并单击Configure/ Convert to Maven Project

于 2018-10-02T13:10:14.330 回答