【问题标题】:How to fix "JAR will be empty - no content was marked for inclusion!" maven-jar-plugin?如何修复“JAR 将为空 - 没有内容被标记为包含!” maven-jar-插件?
【发布时间】:2019-03-26 07:41:24
【问题描述】:

当我运行 maven-jar-plugin, jar:jar 我有这个警告和空 jar 文件

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

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

我该如何解决?我试图在其他问题中找到解决方案,但所有解决方案都不起作用

这是我的 pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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>com.actticus.instdbparse</groupId>
    <artifactId>instDBParse</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>com.github.igor-suhorukov</groupId>
            <artifactId>instagramscraper</artifactId>
            <version>2.2</version>
        </dependency>
        <dependency>
            <groupId>org.brunocvcunha.instagram4j</groupId>
            <artifactId>instagram4j</artifactId>
            <version>1.8</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.14</version>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.0</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <index>true</index>
                        <manifest>
                            <mainClass>com.actticus.instdbparse.Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.6.0</version>
                <configuration>
                    <cleanupDaemonThreads>false</cleanupDaemonThreads>
                    <classpathScope>test</classpathScope>
                    <mainClass>Main</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <id>run-selenium</id>
                        <phase>integration-test</phase>
                        <goals><goal>java</goal></goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

【问题讨论】:

标签: java maven


【解决方案1】:

不要运行mvn jar:jar,而是运行mvn clean packagejar:jar 目标只是打包——没有生命周期,就没有任何东西可以打包。

查找“Maven 生命周期”以获取更多背景信息。

【讨论】:

  • 我使用 maven 和 IntelliJ IDEA,clean:clean 是吗?
  • 没有。您需要致电clean package。正是这样。这些是阶段。不要将个人目标称为clean:clean。 (经验法则:不要尝试使用包含: 的任何内容进行构建)。
  • 您的意思是“执行”还是“构建”?从 cmd 构建是 mvn clean install
  • 不,我的意思是,例如“java -jar instdbparse.jar”
  • @Actticus 但这与问题有什么关系?对于独立 jar,查找 maven shade 插件或 maven 程序集插件。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-01-05
  • 1970-01-01
  • 2013-11-05
  • 1970-01-01
  • 1970-01-01
  • 2017-01-11
  • 1970-01-01
相关资源
最近更新 更多