【问题标题】:WARNING JAR will be empty - no content was marked for inclusion警告 JAR 将为空 - 没有内容被标记为包含
【发布时间】:2019-07-16 19:33:24
【问题描述】:

尝试使用 Cmd 打包,得到 [WARNING] JAR 将是空的 - 没有内容被标记为包含!

构建成功,但生成的 jar 文件为空,根据警告

抱歉,我也尝试了其他解决方案,终于来到了这里,我是 java 和 maven 的新手。请帮忙

我的 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.mto</groupId>
    <artifactId>rlso_smoke</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <name>rlso_smoke</name>
    <!-- FIXME change it to the project's website -->
    <url>http://www.example.com</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.14.3</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>4.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>4.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.6.0</version>
        </dependency>
    </dependencies>

    <build>
        <pluginManagement><!-- lock down plugins versions to avoid using Maven 
                defaults (may be moved to parent pom) -->
            <plugins>
                <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
                <plugin>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>3.1.0</version>
                </plugin>
                <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>3.0.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                </plugin>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.22.1</version>
                    <configuration>
                        <suiteXmlFiles>
                            <suiteXmlFile>testng.xml</suiteXmlFile>
                        </suiteXmlFiles>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>3.0.2</version>

                </plugin>
                <plugin>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>2.5.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>2.8.2</version>
                </plugin>

                <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
                <plugin>
                    <artifactId>maven-site-plugin</artifactId>
                    <version>3.7.1</version>
                </plugin>
                <plugin>
                    <artifactId>maven-project-info-reports-plugin</artifactId>
                    <version>3.0.0</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

当尝试 mvn clean install -DskipTests 时会发出警告,因为 jar 是空的

当我使用以下内容更新 pom.xml (maven-jar-plugin) 时

                <plugin>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>3.0.2</version>
                    <configuration>
                        <classesDirectory>src</classesDirectory>
                        <excludes>
                            <exclude>**</exclude>
                        </excludes>
                    </configuration>
                </plugin>

Jar 生成时没有错误,但大小为 3KB - 对吗?

但是当我尝试执行 jar 时

java -jar rlso_smoke-0.0.1-SNAPSHOT.jar

出现以下错误:

no main manifest attribute, in rlso_smoke-0.0.1-SNAPSHOT.jar

我已经看到需要 Main 类的其他答案。但我也看到 testng 不需要主类。

【问题讨论】:

    标签: java maven selenium-webdriver executable-jar


    【解决方案1】:
                        <excludes>
                            <exclude>**</exclude>
                        </excludes>
    

    这是 maven-jar-plugin 从 jar 中排除所有文件的指令。因此,空罐子被生产出来。删除此部分,然后重试。

    【讨论】:

    • 使用排除项我能够生成 jar,但 jar 的大小非常小,例如 3KB,采纳了您的建议并删除了排除项,并且 jar 生成的大小更大,约为 5MB。但是当我像&gt;java -jar rlso_smoke-0.0.1-SNAPSHOT.jar 这样运行jar 时,我得到no main manifest attribute, in rlso_smoke-0.0.1-SNAPSHOT.jar
    • 这意味着没有带有主类属性的清单。看看这里如何创建清单文件mkyong.com/maven/how-to-create-a-manifest-file-with-maven
    • 我正在使用 testng 框架,我认为 testng 不需要 Main 类。不管怎样,我添加了一个Runner classMain 仍然得到no main manifest attribute, in rlso_smoke-0.0.1-SNAPSHOT.jar。还将查看上述链接
    • 我用 manifest ``` org.apache.maven.pluginsmaven-jar-plugin 更新了jar包3.0.2com.rlso.internal.RunTests ``` 现在错误是Error: Could not find or load main class com.rlso.internal.RunTests
    • 如果我使用 -cp 选项运行 java -cp -jar rlso_smoke-0.0.1-SNAPSHOT.jar -verbose 我会得到不同的错误 Error: Could not find or load main class rlso_smoke-0.0.1-SNAPSHOT.jar 我想我没有正确包装它请让我知道 jar 包装中是否有任何问题,而不是给出正确的类路径或其他东西。
    猜你喜欢
    • 1970-01-01
    • 2013-11-05
    • 1970-01-01
    • 2019-01-05
    • 1970-01-01
    • 2018-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多