错误:“Elevator.jar 中没有主要清单属性"; [英] Error: "no main manifest attribute, in Elevator.jar"
问题描述
我正在开发一个私有的 Discord 机器人,在那里我使用 json 文件来存储值.我的机器人在 IntelliJ 中完美运行.我使用 Artifact 功能创建了一个 .jar 文件,但是当我尝试运行它时,出现错误:no main manifest attribute, in Elevator.jar
.我使用 Git bash 使用命令 java -jar Elevator.jar
运行它.我使用 maven、一个 json 库和一个 JDA 库(用于 Discord 集成).
I am working on a private Discord bot, where I use json files to store values. My bot runs perfectly in IntelliJ. I created a .jar file using the Artifact feature, but when I try to run it, I get the error: no main manifest attribute, in Elevator.jar
. I used Git bash to run it using the command java -jar Elevator.jar
. I use maven, a json library and a JDA library (for Discord integration).
我的 pom.xml 文件是否错误,或者我不能将 json 文件用于 .jar?如果是这样,我如何在不运行 intellij 的情况下执行我的代码?如果我需要添加更多代码或提供更多信息,请询问.
Is my pom.xml file wrong, or can I not use json files for a .jar? if so, how can I execute my code without running intellij? If I need to add more code or give more info please ask.
注意事项:
- 包裹是sebastiaan.Elevator
- 我使用了文件 ->项目结构->文物 ->添加 ->JAR ->从具有依赖项的模块中,选择正确的主类并按 OK.然后我点击 Build ->构建工件 ->构建以创建文件
我的 MANIFEST.MF:
My MANIFEST.MF:
Manifest-Version: 1.0
Main-Class: sebastiaan.Elevator.Main
我的 pom.xml:
My 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>groupId</groupId>
<artifactId>Elevator</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
推荐答案
需要在pom.xml中添加主类清单
You need to add a main class manifest in the pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
...
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
</configuration>
...
</plugin>
</plugins>
</build>
查看更多示例此处
这篇关于错误:“Elevator.jar 中没有主要清单属性";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!