RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 713012
Accepted
Lezenford
Lezenford
Asked:2020-09-01 02:44:57 +0000 UTC2020-09-01 02:44:57 +0000 UTC 2020-09-01 02:44:57 +0000 UTC

错误:运行 jar 时无法找到或加载主类 ActionChecker

  • 772

无法处理 jar 生成。输入:Intellij Idea 项目,通过 maven 生成。直接在java文件夹中有一个类,主要是ActionChecker方法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>test</groupId>
    <artifactId>HKFB-actions</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>HKFB-actions</name>


    <properties>
        <jdk.version>1.8</jdk.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>ActionChecker</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.11</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.12</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <version>6.1.0.jre8</version>
        </dependency>

    </dependencies>

</project>

manifesf.mf 的内容

Manifest-Version: 1.0
Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
Bundle-SymbolicName: org.apache.commons.lang3
Archiver-Version: Plexus Archiver
Built-By: dev@commons.apache.org
Bnd-LastModified: 1394888296110
Implementation-Vendor-Id: org.apache
Main-Class: ActionChecker
Specification-Title: Apache Commons Lang
Bundle-DocURL: http://commons.apache.org/proper/commons-lang/
Include-Resource: META-INF/LICENSE.txt=LICENSE.txt,META-INF/NOTICE.txt
 =NOTICE.txt
Export-Package: org.apache.commons.lang3;version="3.3.1",org.apache.co
 mmons.lang3.builder;version="3.3.1",org.apache.commons.lang3.concurre
 nt;version="3.3.1",org.apache.commons.lang3.event;version="3.3.1",org
 .apache.commons.lang3.exception;version="3.3.1",org.apache.commons.la
 ng3.math;version="3.3.1",org.apache.commons.lang3.mutable;version="3.
 3.1",org.apache.commons.lang3.reflect;version="3.3.1",org.apache.comm
 ons.lang3.text;version="3.3.1",org.apache.commons.lang3.text.translat
 e;version="3.3.1",org.apache.commons.lang3.time;version="3.3.1",org.a
 pache.commons.lang3.tuple;version="3.3.1"
Bundle-Name: Apache Commons Lang
Implementation-Title: Apache Commons Lang
Bundle-Description: Apache Commons Lang, a package of Java utility cla
 sses for the  classes that are in java.lang's hierarchy, or are consi
 dered to be so  standard as to justify existence in java.lang.
Implementation-Version: 3.3.1
Specification-Vendor: The Apache Software Foundation
Bundle-ManifestVersion: 2
Bundle-Vendor: The Apache Software Foundation
Tool: Bnd-2.1.0.20130426-122213
Implementation-Vendor: The Apache Software Foundation
Bundle-Version: 3.3.1
X-Compile-Target-JDK: 1.6
Implementation-Build: tags/LANG_3_3_1_RC1@r1577854; 2014-03-15 13:58:1
 0+0100
X-Compile-Source-JDK: 1.6
Created-By: Apache Maven Bundle Plugin
Build-Jdk: 1.7.0_45
Specification-Version: 3.3.1

但是当通过 java -jar ***.jar 运行时,它会抛出一个错误 Error: Could not find or load main class ActionChecker

我究竟做错了什么?生成的工件具有此清单,该类本身也存在,它位于 ActionChecker.class 的根目录,但工件不想启动...

我也无法混淆主要方法的方法代码......有趣的是,我通过 maven 生成 - 我发誓库没有拉起,尽管 pom.xml 包含有关库的信息。我通过 intellij 的想法产生 - 发誓不可能找到必要的课程......精神错乱!

public static void main(String[] args) {
        System.out.println("--Обработчик выгрузки акций банка ХКФБ--");
        try {
            System.out.println("Устанавливается соединение с БД, пожалуйста подождите");
            connection = new JDBCConnection();
            System.out.println("Соединение с БД установлено");
        } catch (SQLException e) {
            System.out.println("Ошибка соединения с БД! Приложение будет закрыто");
            e.printStackTrace();
            close();
            return;
        }
        String command;
        while (true) {
            System.out.println("Основное меню. Введите команду, чтобы продолжить. Введите Help для помощи");
            try {
                command = ConsoleHelper.readString();
                if (command.toLowerCase().equals("exit")) {
                    close();
                    return;
                } else if (command.toLowerCase().equals("add")) {
                    add();
                } else if (command.toLowerCase().equals("help")) {
                    help();
                } else if (command.toLowerCase().equals("equals")) {
                    equalsActions();
                } else
                    System.out.println("Команда не распознана");
            } catch (IOException e) {
                System.out.println("Ошибка! Приложение будет закрыто!");
                e.printStackTrace();
                System.exit(0);
            }
        }

    }

一切,想通了,通过收集

<plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>ActionChecker</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id> <!-- this is used for inheritance merges -->
                        <phase>package</phase> <!-- bind to the packaging phase -->
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

结果,依赖项和主项都被拉起

java
  • 1 1 个回答
  • 10 Views

1 个回答

  • Voted
  1. Best Answer
    DaysLikeThis
    2020-09-01T11:54:20Z2020-09-01T11:54:20Z

    可能是 pom.xml 中的类名拼写错误,或者 main 方法的签名不匹配

    public class ActionChecker {
        public static void main(String[] args) {
            System.out.println("123");
        }
    }
    

    在您的帮助下构建后的结果

    Building jar: ../target/HKFB-actions-1.0-SNAPSHOT.jar
    

    发射

    java -jar HKFB-actions-1.0-SNAPSHOT.jar
    

    结果

    123
    

    我将存储库中的插件版本插入 pom.xml:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>3.0.2</version>
        <configuration>
            <archive>
                <manifest>
                    <addClasspath>true</addClasspath>
                    <mainClass>ActionChecker</mainClass>
                </manifest>
            </archive>
        </configuration>
    </plugin>
    <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.0</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
    </plugin>
    
    • 1

相关问题

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    Python 3.6 - 安装 MySQL (Windows)

    • 1 个回答
  • Marko Smith

    C++ 编写程序“计算单个岛屿”。填充一个二维数组 12x12 0 和 1

    • 2 个回答
  • Marko Smith

    返回指针的函数

    • 1 个回答
  • Marko Smith

    我使用 django 管理面板添加图像,但它没有显示

    • 1 个回答
  • Marko Smith

    这些条目是什么意思,它们的完整等效项是什么样的

    • 2 个回答
  • Marko Smith

    浏览器仍然缓存文件数据

    • 1 个回答
  • Marko Smith

    在 Excel VBA 中激活工作表的问题

    • 3 个回答
  • Marko Smith

    为什么内置类型中包含复数而小数不包含?

    • 2 个回答
  • Marko Smith

    获得唯一途径

    • 3 个回答
  • Marko Smith

    告诉我一个像幻灯片一样创建滚动的库

    • 1 个回答
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Алексей Шиманский 如何以及通过什么方式来查找 Javascript 代码中的错误? 2020-08-03 00:21:37 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    user207618 Codegolf——组合选择算法的实现 2020-10-23 18:46:29 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5