RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-245391

Lezenford's questions

Martin Hope
Lezenford
Asked: 2020-09-01 02:44:57 +0000 UTC

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

  • 1

无法处理 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 个回答
  • 10 Views
Martin Hope
Lezenford
Asked: 2020-04-21 01:47:15 +0000 UTC

在 jTextField 中设置文本

  • 0

有问题。摆动界面。它有几个 jtexfield 形状。以下是关于表格的内容:

portTextField.setDocument(new PortDocument()); //устанавливаем ограничение на ввод в поле

private static class PortDocument extends PlainDocument { //класс для ограничения длинны ввода для порта
        @Override
        public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
            String chars = "0123456789";
            if (chars.contains(str)) {
                if (getLength() < 5) { //порт не более 5 символов (0-65535)
                    super.insertString(offs, str, a);
                }
            }
        }
    }

在这里,当尝试做

portTextField.setText(String.valueOf(port));

运行后值不会出现在字段中。尽管传输了数字,但在本文档中,输入是完全允许的。问题。如何限制字段只能输入数字且长度不能超过5,同时又能通过代码向该字段插入值?

下面是完整的代码:

 public SettingFrame(String host, int port, int start, int end) /*throws HeadlessException*/ { //конструктор окна со считанными параметрами
        jFrame = this; //устанавливаем соответсвие для удобства
        hostTextField.setText(host); //устанавливаем значение хоста
        portTextField.setText(String.valueOf(port)); //устанавливаем значение порта
        if (start ==0 && end == 0) { //если режим ND не активирован
            availableDB.setSelected(false);
            startNDTextField.setEnabled(false);
            endNDTextField.setEnabled(false);
        }else { //если режим ND активирован
            availableDB.setSelected(true);
            startNDTextField.setEnabled(true);
            endNDTextField.setEnabled(true);
            startNDTextField.setText(String.valueOf(start));
            endNDTextField.setText(String.valueOf(end));
        }
        init(); //инициируем


 private void init() { //инициация. Общая для обоих конструкторов
        jFrame.add(rootPanel); //добавляем к фрейму панель
        startNDTextField.setDocument(new NDDocument()); //устанавливаем ограничение на ввод в поле
        endNDTextField.setDocument(new NDDocument()); //устанавливаем ограничение на ввод в поле
        portTextField.setDocument(new PortDocument()); //устанавливаем ограничение на ввод в поле
        this.pack(); //устанавливаем размеры
        this.setLocationRelativeTo(null); //перемещаем окно в центр рабочего стола
        this.setResizable(false); //запрещаем изменять размер окна
        this.setVisible(true); //отображаем окно
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); //устанавливаем функцию кнопки закрытия - выход из программы
...

最小足够的自我复制方法是:

import javax.swing.*;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;


public class Test {
    public static void main(String[] args) {
        JTextField jTextField = new JTextField();
        jTextField.setText("12");
        System.out.println(jTextField.getText().length());
        jTextField.setDocument(new PortDocument());
        System.out.println(jTextField.getText().length());

    }

    private static class PortDocument extends PlainDocument { //класс для ограничения длинны ввода для порта
        @Override
        public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
            String chars = "0123456789";
            if (chars.contains(str)) {
                if (getLength() < 5) { //порт не более 5 символов (0-65535)
                    super.insertString(offs, str, a);
                }
            }
        }
    }


}
swing
  • 2 个回答
  • 10 Views

Sidebar

Stats

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

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +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
    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