无法处理 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>
结果,依赖项和主项都被拉起