问题描述
我在使用Maven将Kotlin项目与JAR文件具有某些依赖项组装时遇到问题.
我如何将项目组装到JAR:
How am i assembling project to JAR:
RightPanel -> MavenProjects -> Lifecycle -> package -> run
当我运行JAR文件时:
When i running JAR file:
java -jar path.jar
我遇到以下错误:
no main manifest attribute, in path.jar
我在此处中添加了maven-assembly-plugin
所以我的插件目录如下:
<build>
<sourceDirectory>src/main/kotlin</sourceDirectory>
<testSourceDirectory>src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals> <goal>single</goal> </goals>
<configuration>
<archive>
<manifest>
<mainClass>${main.class}</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
main.class
属性在此处定义:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.version>1.1.51</kotlin.version>
<junit.version>4.12</junit.version>
<main.class>ru.icarumbas.main.HelloKt</main.class>
</properties>
一些事实:
-
Hello.kt
是入门类,它很有趣main(...){}
- 当我取消归档JAR时,它具有META-INF文件夹.
Hello.kt
is starter class and it has funmain(...){}
- When i unarchive JAR it has META-INF folder.
版本:
- 平台:Mac OS
- 科特林版本:1.1.51
- Maven版本:4.0.0
也许我想念一些东西.我已经看过很多类似的问题,但它们并没有帮助我.因此,如果您想查看更多代码,请不要将其标记为重复并写评论.我没有显示完整的pom.xml
文件,因此,如果您想查看完整的文件,请写信给我.
Maybe i'm missing something. I've already looked on a lot of questions alike this, and they didn't help me. So please don't mark this as duplicate and write a comment if you want to see more code. I didn't show my full pom.xml
file so write me if you want to see it full.
推荐答案
我在Kotlin和Maven中遇到了此类问题.我已经通过以下方式(Application.kt)解决了它:
I've got such problems with kotlin and maven.I've solved it in following way (Application.kt):
package org.somepackage
open class Application {
companion object {
@JvmStatic fun main(args: Array<String>) {
// something..
}
}
}
-所以首先我写了一个kotlin类,里面有main.
-- So first i've written the kotlin class with main inside it.
其次,按照您的情况,通过以下方式<main.class>org.somepackage.Application</main.class>
Secondly as in your case defined the main class in props in a following way <main.class>org.somepackage.Application</main.class>
在执行mvn clean install命令后,我得到了必要的someapp-1.0-SNAPSHOT-jar-with-dependencies.jar可以正常工作.
After mvn clean install command finished i've got the necessary someapp-1.0-SNAPSHOT-jar-with-dependencies.jar which was able to work.
最后请注意,您运行的正是jar-with-dependencies.jar(不是像app-1.0-SNAPSHOT.jar这样的剥离版本).
And at the end please pay attention that you run exactly jar-with-dependencies.jar (not a stripped version like a app-1.0-SNAPSHOT.jar).
这篇关于Kotlin + Maven组装:无主要清单属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!