如何从 IntelliJ IDEA 正确构建 JAR?

发布于 2024-07-25 23:10:45 字数 165 浏览 15 评论 0原文

我有一个包含单个模块和一些依赖项的项目。 我想在一个单独的目录中创建一个 JAR,其中包含已编译的模块。 此外,我希望在我的模块旁边存在依赖项。

无论我如何扭转 IntelliJ 的“构建 JAR”过程,我的模块的输出都显示为空(除了 META-INF 文件)。

I have a project that contains a single module, and some dependencies.
I'd like to create a JAR, in a separate directory, that contains the compiled module. In addition, I would like to have the dependencies present beside my module.

No matter how I twist IntelliJ's "build JAR" process, the output of my module appears empty (besides a META-INF file).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(24

若能看破又如何 2024-08-01 23:10:46

通过 Maven,你可以使用这个插件:

 <build>
    <plugins>

        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>[path you class main]</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase> 
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

With Maven you can use this plugin:

 <build>
    <plugins>

        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>[path you class main]</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase> 
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
多彩岁月 2024-08-01 23:10:46

在 IntelliJ 终端中使用

mvn clean package spring-boot:repackage

上面的命令。 它生成一个带有可执行 Jar 的目标文件。

Using

mvn clean package spring-boot:repackage

type above command inside IntelliJ Terminal. It generates a Target file with Executable Jar.

满天都是小星星 2024-08-01 23:10:46

Idea 8.1.3

Jar 没问题,因为“output”目录(project/out/product//)中有已编译的输出,

我猜,您必须在构建

依赖项的 jar 之前运行“make”,只需检查“show library”并选择你想要什么。

Idea 8.1.3

Jar is ok, since there is compiled output in 'output' directory (project/out/production//)

I guess, you have to run 'make' before building jar

for dependencies just check "show library" and choose what you want.

夏了南城 2024-08-01 23:10:46

这里是IntelliJ IDEA 2018.3 Help的官方解答。 我尝试过并且成功了。

从模块构建 JAR 文件;

  1. 在主菜单上,选择“构建”|“构建”。 构建工件。

  2. 从下拉列表中,选择 JAR 类型的所需工件。
    该列表显示了为当前项目配置的所有工件。 要构建所有已配置的工件,请选择“构建全部”
    工件选项。

Here is the official answer of IntelliJ IDEA 2018.3 Help. I tried and It worked.

To build a JAR file from a module;

  1. On the main menu, choose Build | Build Artifact.

  2. From the drop-down list, select the desired artifact of the type JAR.
    The list shows all the artifacts configured for the current project. To have all the configured artifacts built, choose the Build all
    artifacts option.

幼儿园老大 2024-08-01 23:10:46

我的问题是这样的:我使用Intellij IDEA(尝试了不同的版本)+ Gradle。
当我编译项目并构建 artifaf jar 时,如上面的响应所示,我收到一个错误 - “没有主清单属性......”

这个解决方案对我有用(特别感谢 Thilina Ashen Gamage(见上文)的提示) :

摘录 - 如果您使用外部库并通过项目设置 - 工件 - 添加 (+) - Jar - 来自具有依赖项的模块构建项目,那么可能是因为 META-INF 文件夹中的程序错误MANIFEST_MF 文件不包括 jar。 为了避免它创建 jar 文件。

项目设置 - 工件 - 添加 (+) - Jar - EMPTY JAR。 META-INF 文件夹将添加到资源文件夹中。 然后选择您的主课程。 您将看到以下 jar 结构:
注意存在文件夹 META-INF
请注意文件夹 META-INF 的存在
然后您可以构建项目并构建工件。 该解决方案也适用于 javaFX 应用程序。

My problem was this: I used Intellij IDEA (tried different versions) + Gradle.
When I compiled the project and builded artifacf jar, as indicated in the above responses, I received an error - "no main manifest attrubute ..."

This solution worked for me (special thanks to Thilina Ashen Gamage (see above) for tip):

Excerpt - if you use external libraries and build a project through Project Settings - Artifacts - Add (+) - Jar - From modules with dependencies, then probably because of a program bug the META-INF folder with MANIFEST_MF file not including to jar. To avoid it create EMPTY jar file.

Project Settings - Artifacts - Add (+) - Jar - EMPTY JAR. META-INF folder will added to resources folder. Then select your main class. You will see following jar structure:
note the presence of a folder META-INF
Note the presence of a folder META-INF
Then you can build your project and build artifacts. This solution worked for javaFX applications too.

流年里的时光 2024-08-01 23:10:46

您可能想看看 Maven (http://maven.apache.org)。 您可以将其用作应用程序的主要构建过程,也可以仅通过“编辑配置”对话框执行某些任务。 如果您希望将所有依赖项包含在一个自可执行 JAR 中,那么在 Maven 中创建模块 JAR 的过程相当简单。

如果您以前从未使用过 Maven,那么您需要阅读使用 Maven 进行更好的构建

You might want to take a look at Maven (http://maven.apache.org). You can use it either as the main build process for your application, or just to perform certain tasks through the Edit Configurations dialog. The process of creating a JAR of a module within Maven is fairly trivial, if you want it to include all the dependencies in a self-executable JAR that is trivial as well.

If you've never used Maven before then you want to read Better Builds With Maven.

罪歌 2024-08-01 23:10:46

如果您在项目中使用第三方库,或者在正确创建 MANIFEST.MF 文件时遇到问题,则在运行使用

File > Project Structure > Artifacts > '+' > JAR > From modules with dependencies > .....

上述方法生成的 JAR 文件时可能会出现冲突。

相反,我建议您创建一个空 JAR 并手动将所有其他元素添加到输出根目录。 有关此方法的精彩博客文章可以在这里找到: http://karthicraghupathi.com/2016/07/10/creating-an-executable-jar-in-intellij-idea/ 我尝试了那里提到的步骤,一切对我来说都很好!

If you are using third party libraries with your project or if you have problems with creating MANIFEST.MF file properly, there can be conflicts when running JAR files generated using

File > Project Structure > Artifacts > '+' > JAR > From modules with dependencies > .....

method mentioned above.

Instead I suggest you to create an empty JAR and add all other elements to the output root manually. A wonderful blog article for this method can be found here: http://karthicraghupathi.com/2016/07/10/creating-an-executable-jar-in-intellij-idea/ I tried the steps mentioned there and everything worked fine for me!

难得心□动 2024-08-01 23:10:46

其他一些答案是无用的,因为一旦您从 Maven 项目重新导入 IntelliJ IDEA 项目,所有更改都将丢失。

jar 的构建需要由运行/调试配置触发,而不是由项目设置触发。

Jetbrains 在这里对如何完成此任务有一个很好的描述:

https://www.jetbrains .com/help/idea/maven.html

向下滚动到名为“配置 Maven 目标的触发器”的部分。

(他们描述的唯一缺点是他们的屏幕截图采用默认的黑白配色方案,而不是超级棒的 darcula 主题。呃!)

所以,基本上,你要做的就是打开“Maven 项目”面板中,您会找到感兴趣的项目(在您的情况下,是构建 jar 的项目),在它下面您会找到要执行的 Maven 目标(通常是“package”目标创建 jars),您打开它的上下文菜单(在 Windows 计算机上右键单击),您可以选择“在运行/调试之前执行...”选项,它将引导您从那里开始。 真的很容易。

Some of the other answers are useless because as soon as you re-import the IntelliJ IDEA project from the maven project, all changes will be lost.

The building of the jar needs to be triggered by a run/debug configuration, not by the project settings.

Jetbrains has a nice description of how you can accomplish this here:

https://www.jetbrains.com/help/idea/maven.html

Scroll down to the section called "Configuring triggers for Maven goals".

(The only disadvantage of their description is that their screenshots are in the default black-on-white color scheme instead of the super-awesome darcula theme. Ugh!)

So, basically, what you do is that you open the "Maven Projects" panel, you find the project of interest, (in your case, the project that builds your jar,) underneath it you find the maven goal that you want to execute, (usually the "package" goal creates jars,) you open up the context menu on it, (right-click on a Windows machine,) and there will be an "Execute before Run/Debug..." option that you can select and it will take you by the hand from there. Really easy.

花之痕靓丽 2024-08-01 23:10:46

如果您尝试使用 kotlin 构建 jar,则需要创建一个 src/main/java 文件夹并使用该文件夹作为 META-INF 文件夹的位置。

In case you are trying to build a jar with kotlin you need to create a src/main/java folder and use this folder as a location for the META-INF folder.

时光倒影 2024-08-01 23:10:46

如果您正在阅读此答案,因为您遇到“找不到资源文件”错误,请尝试以下操作:

  1. 文件 -> 项目结构-> Artiface-> 新建,类型为其他
  2. 给它一个好听的名字,然后在输出布局中,按创建存档创建一个新的jar,然后再次给它一个好听的名字;)
  3. 单击您想要的jar刚刚添加,将编译的模块输出添加到 jar 中。
  4. 再次单击 jar,在下部窗格中选择项目路径并添加清单文件,然后设置正确的主类和类路径。
  5. 单击添加库文件,然后选择您需要的库(可以使用Ctrl+A全选)。
  6. 构建-> 构建神器-> 清洁& 构建并查看错误是否消失。

In case you are reading this answer because you are facing "resource file not found" error, try this:

  1. File -> Project Structure -> Artiface -> New, type is Other.
  2. Give it a nice name, and in the Output Layout, press Create Archive to create a new jar, and again, give it a nice name ;)
  3. Click on the jar you just added, add your compiled module output in the jar.
  4. Click on the jar again, in the lower pane, select your project path and add Manifest File then set correct Main Class and Class Path.
  5. Click Add Library Files, and select libraries you need (you can use Ctrl+A to select all).
  6. Build -> Build Artifact -> Clean & Build and see if the error is gone.
一指流沙 2024-08-01 23:10:46

使用 Gradle 构建您的项目,然后 jar 位于构建文件中。 以下是有关如何使用 Gradle 构建 .jar 文件的 Stack Overflow 链接。

使用 Gradle 和构建的 Java 项目Intellij IDEA 中的 jar 文件 - 如何?

Use Gradle to build your project, then the jar is within the build file. Here is a Stack Overflow link on how to build .jar files with Gradle.

Java project with Gradle and building jar file in Intellij IDEA - how to?

如果没有 2024-08-01 23:10:46

我尝试了大部分给出的答案,但在我的情况下,“out”文件夹(包含 jar 文件)没有被创建。 这样就完成了工作:

构建 -> 构建工件 -> (你会看到类名)-> 现在构建

,“out”文件夹已创建,jar 文件位于其中。

I tried most of the given answers, but in my case "out" folder (which contains jar file) was not getting created. So this did the job :

Build -> Build Artifacts -> (you will see the class name) -> Build

Now, "out" folder was created and jar file was in it.

全部不再 2024-08-01 23:10:46

如果您使用的是新的测试版 IntelliJ UI,则上述解决方案将需要修改。

目前,在新的测试版 IntelliJ UI 中,存在一个错误:如果您单击构建工件菜单,什么也不会发生。

但是,如果您使用箭头键导航到“构建”按钮,然后按键盘上的“Enter”键,它将起作用。

或者您可以执行以下操作:

您必须按 Shift+Shift 键输入 [Build Artifacts...] > 然后使用箭头键导航构建工件浮动菜单并按 Enter 键。

错误跟踪器:https:/ /youtrack.jetbrains.com/issue/IDEA-316889/Build-artifacts-inactive-if-hamburger-menu-is-on

希望这可以帮助某人避免我在尝试将 JAR 文件获取到时所经历的痛苦被建造。

If you're using the new beta IntelliJ UI, the above solutions will require modification.

Currently, in the new beta IntelliJ UI, there is a bug where if you click on the "build" button in the build artifacts menu, nothing will happen.

However, if you use arrow keys to navigate to the "build" button, and then press "enter" on your keyboard, it will work.

or you can do the following:

You have to shift+shift type [Build Artifacts...] > then use arrow keys to navigate build artifact floating menu and hit enter.

Bug tracker: https://youtrack.jetbrains.com/issue/IDEA-316889/Build-artifacts-inactive-if-hamburger-menu-is-on

Hopefully this saves someone from the hour of pain I experienced trying to get my JAR file to be built.

雪花飘飘的天空 2024-08-01 23:10:46

如果您正在处理 spring/mvn 项目,您可以使用以下命令:

mvn package -DskipTests

jar 文件将保存在目标目录中。

If you are working on spring/mvn project you can use this command:

mvn package -DskipTests

The jar file will be saved on target directoy.

寄与心 2024-08-01 23:10:46

Ant和Maven被广泛使用。 我更喜欢 Ant,我觉得它更轻量级,并且开发人员可以更好地控制。 有些人会认为这是它的缺点:-)

Ant and Maven are widely used. I prefer Ant, I feel it's more lightweight and you the developer are more in control. Some would suggest that's its downside :-)

鲜肉鲜肉永远不皱 2024-08-01 23:10:45

说明:

文件 -> 项目结构 -> 项目设置 -> 文物 -> 单击+(加号)-> 罐子 -> 从具有依赖关系的模块...

如果需要使 jar 可运行,请选择一个主类(带有 main() 方法的类)。

选择提取到目标 Jar

单击确定

单击应用/确定

上面将“骨架”设置为jar 将被保存到。 要实际构建并保存它,请执行以下操作:

Build -> 构建工件 -> 构建

尝试从以下位置提取 .jar 文件:

Instructions:

File -> Project Structure -> Project Settings -> Artifacts -> Click + (plus sign) -> Jar -> From modules with dependencies...

Select a Main Class (the one with main() method) if you need to make the jar runnable.

Select Extract to the target Jar

Click OK

Click Apply/OK

The above sets the "skeleton" to where the jar will be saved to. To actually build and save it do the following:

Build -> Build Artifact -> Build

Try Extracting the .jar file from:

????ProjectName
 ┗ ????out
   ┗ ????artifacts
     ┗ ????ProjectName_jar
        ┗ ????ProjectName.jar

References:

莳間冲淡了誓言ζ 2024-08-01 23:10:45

这在2017年仍然是一个问题,我希望它能帮助那里的人!
我发现在 IntelliJ 2017.2 1 下创建工作 jar-s 的两种可能性

。 从 IntelliJ 创建工件:

  • 转到项目结构:

文件菜单

  • 创建一个新工件:

< img src="https://i.sstatic.net/wEbRv.png" alt="创建新工件">

  • 选择主类,并确保更改清单文件夹:

在此处输入图像描述

您必须更改清单目录:

<project folder>\src\main\java 

将“java”替换为“resources”

<project folder>\src\main\resources

这应该是这样的:

新清单的正确方式

  • 然后选择要打包到 jar 中的依赖项,或靠近您的 jar 文件

  • 要构建您的工件,请转到构建工件并选择“重建”。 它将创建一个包含您的 jar 文件及其依赖项的“out”文件夹。

输入图像描述这里

2. 使用 maven- assembly-plugin

将构建部分添加到 pom 文件

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <finalName>ServiceCreate</finalName>
                    <appendAssemblyId>false</appendAssemblyId>
                    <archive>
                        <manifest>
                            <mainClass>com.svt.optimoo.App</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </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>
  • 创建新的运行/调试配置:

创建新的运行/调试配置:

  • 选择应用程序:

选择应用

  • 填写表单
  • 添加构建后最后执行的“ assembly:single” Maven 目标

在此处输入图像描述

最终设置

  • 保存,然后运行

​​在此处输入图像描述

此过程将在“target”文件夹下创建 jar 文件

JAR 文件位置

This is still an issue in 2017, I hope it will help somebody out there!
I found 2 possibilities to create working jar-s under IntelliJ 2017.2

1. Creating artifact from IntelliJ:

  • Go to project structure:

File menu

  • Create a new artifact:

Create a new artifact

  • Select the main class, and be sure to change the manifest folder:

enter image description here

You have to change manifest directory:

<project folder>\src\main\java 

replace "java" with "resources"

<project folder>\src\main\resources

This is how it should look like:

correct way for new manifest

  • Then you choose the dependencies what you want to be packed IN your jar, or NEAR your jar file

  • To build your artifact go to build artifacts and choose "rebuild". It will create an "out" folder with your jar file and its dependencies.

enter image description here

2. Using maven-assembly-plugin

Add build section to the pom file

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <finalName>ServiceCreate</finalName>
                    <appendAssemblyId>false</appendAssemblyId>
                    <archive>
                        <manifest>
                            <mainClass>com.svt.optimoo.App</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </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>
  • Create a new run/debug configuration:

Create a new run/debug configuration:

  • Choose application:

Choose application

  • Fill in the form
  • Add the "assembly:single" maven goal after build to be executed last

enter image description here

Final setup

  • Save it, then run

enter image description here

This procedure will create the jar file under the "target" folder

JAR file location

梦与时光遇 2024-08-01 23:10:45

我最近遇到了这个问题,并且认为如果任何先前的解决方案或链接缺少细节,这些步骤很容易遵循。

如何使用 IntelliJ IDEA 14.1.5 创建 .jar

  1. 文件 > 保存全部。
  2. 使用 main 方法运行驱动程序或类。
  3. 文件> 项目结构。
  4. 选择选项卡“工件”。
  5. 单击窗口顶部附近的绿色加号按钮。
  6. 从添加下拉菜单中选择 JAR。 选择“来自具有依赖项的模块”
  7. 选择主类。
  8. 单选按钮应选择“提取到目标 JAR”。 按确定。
  9. 选中“Build on make”框,
  10. 然后按应用并确定。
  11. 从主菜单中,选择构建下拉列表。
  12. 选择选项构建工件。

I recently had this problem and think these steps are easy to follow if any prior solution or link is missing detail.

How to create a .jar using IntelliJ IDEA 14.1.5:

  1. File > Save All.
  2. Run driver or class with main method.
  3. File > Project Structure.
  4. Select Tab "Artifacts".
  5. Click green plus button near top of window.
  6. Select JAR from Add drop down menu. Select "From modules with dependencies"
  7. Select main class.
  8. The radio button should be selecting "extract to the target JAR." Press OK.
  9. Check the box "Build on make"
  10. Press apply and OK.
  11. From the main menu, select the build dropdown.
  12. Select the option build artifacts.
青春有你 2024-08-01 23:10:45

对于那些像我一样受益于图像的人:

文件 -> 项目结构

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

For those that benefit from images as I do:

File -> Project Structure

enter image description here

enter image description here

enter image description here

enter image description here

缱倦旧时光 2024-08-01 23:10:45

下面是 2 个使用 maven 项目的示例,一步一步进行:

方法 1:使用 maven 和 pom.xml 构建 jar 文件

  1. ,新建项目,maven
  2. 创建一个包,在该包内创建一个 java 程序
    输入图像描述此处
  3. 在 pom.xml 中添加 maven-jar-plugin。

    <前><代码> <插件>

    org.apache.maven.plugins
    maven-jar-plugin;
    <版本>3.1.0
    <配置>
    <存档>
    <清单>
    true
    lib/;
    somePackage.sample



屏幕截图:
输入图像描述这里
4.通过单击搜索图标并输入maven,打开maven项目框,
输入图像描述此处

  1. 单击“清理”,然后单击“安装”
    输入图像描述此处

  2. 你的 jar 文件将显示在目标文件夹中
    输入图像描述这里

  3. 使用测试你的罐子
    java -jar

在此处输入图像描述

方法2:使用maven构建jar,无需更改pom.xml

  1. 文件,新建,项目,maven
  2. 创建一个包,在该包内创建一个java程序(同上)
  3. 文件< /kbd>-> 项目结构 -> 项目设置 -> 文物 -> 点击绿色加号 -> 罐子 -> 来自具有依赖关系的模块

非常重要!

MANIFEST.MF 需要位于您的资源文件夹中,并且 Main.Class 需要引用 {package}-{class-name-that-c​​ontains-main-class}

在此处输入图像描述
输入图像描述这里

  1. 然后单击菜单上的构建,构建工件,构建

在此处输入图像描述

  1. 在 out 文件夹中找到 jar

在此处输入图像描述

  1. 运行它:)

在此处输入图像描述

Here are 2 examples with maven project, step by step:

Method 1: Build jar with maven and pom.xml

  1. File, new, project, maven
  2. create a package , create a java program inside that package
    enter image description here
  3. at pom.xml, add maven-jar-plugin.

        <plugin>
            <!-- Build an executable JAR -->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.1.0</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                        <mainClass>somePackage.sample</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    

screen capture:
enter image description here
4. open maven project box by click on the search icon and type maven,
enter image description here

  1. click on clean, then click on install
    enter image description here

  2. your jar file will show up inside the target folder
    enter image description here

  3. test your jar using
    java -jar

enter image description here

Method 2: Build jar with maven without pom.xml change

  1. File, new, project, maven
  2. create a package , create a java program inside that package (same as above)
  3. File -> Project Structure -> Project Settings -> Artifacts -> Click green plus sign -> Jar -> From modules with dependencies

Very important!

The MANIFEST.MF needs to be in your resources folder and the Main.Class needs to refer to {package}-{class-name-that-contains-main-class}

enter image description here
enter image description here

  1. then click build on menu , build artifacts, build

enter image description here

  1. find the jar in the out folder

enter image description here

  1. run it :)

enter image description here

羅雙樹 2024-08-01 23:10:45

当我使用这些解决方案时出现此错误:

java -jar xxxxx.jar

xxxxx.jar 中没有主要清单属性

解决方案是:

您必须更改清单目录:

<project folder>\src\main\java 

将 java 更改为资源

<project folder>\src\main\resources

When i use these solution this error coming:

java -jar xxxxx.jar

no main manifest attribute, in xxxxx.jar

and solution is:

You have to change manifest directory:

<project folder>\src\main\java 

change java to resources

<project folder>\src\main\resources
枯寂 2024-08-01 23:10:45

可能有点晚了,但我设法这样解决了 ->
用winrar打开并删除META-INF文件夹中的ECLIPSEF.RSA和ECLIPSEF.SF,并在MANIFEST.MF中放入“Main-class: main_class_name”(不带“.class”)。 确保在最后一行后按两次“Enter”键,否则它将无法工作。

It is probably little bit late, but I managed to solve it this way ->
open with winrar and delete ECLIPSEF.RSA and ECLIPSEF.SF in META-INF folder, moreover put "Main-class: main_class_name" (without ".class") in MANIFEST.MF. Make sure that you pressed "Enter" twice after the last line, otherwise it won't work.

迷路的信 2024-08-01 23:10:45

我试图从多模块 Kotlin 应用程序构建一个 jar,但遇到了臭名昭著的“无主清单属性”错误。 在 src/main/resources 中创建清单目录也不起作用。

相反,当直接在 src 中创建它时,它会起作用:src/META-INF/MANIFEST.MF

输入图像描述这里

I was trying to build a jar from a multi-module Kotlin app and was getting the notorious 'no main manifest attribute' error. Creating the manifest directory in src/main/resources didn't work either.

Instead, it works when creating it in src directly: src/META-INF/MANIFEST.MF.

enter image description here

ぽ尐不点ル 2024-08-01 23:10:45

输入图片这里的描述

正如上面的人所说,但我必须注意一点。
您必须选中该复选框:

包含在项目构建中

enter image description here

As the people above says, but I have to note one point.
You have to check the checkbox:

Include in project build

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文