我已经编写了一个简单的kotlin源文件以便开始使用,还有一个gradle脚本文件.但我无法弄清楚如何将主要功能添加到清单中,以便jar可以自行执行.
这是我的build.gradle脚本:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:0.9.66'
}
}
apply plugin: "kotlin"
repositories {
mavenCentral()
}
dependencies {
compile 'org.jetbrains.kotlin:kotlin-stdlib:0.9.66'
}
jar {
manifest {
attributes 'Main-Class': 'com.loloof64.kotlin.exps.ExpsPackage'
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的com.loloof64.kotlin.exps.Multideclarations.kt
package com.loloof64.kotlin.exps
class Person(val firstName: String, val lastName: String) {
fun component1(): String {
return firstName
}
fun component2(): String {
return lastName
}
}
fun main(args: Array < String > ) {
val(first, last) = Person("Laurent", "Bernabé")
println("First name : $first - Last …Run Code Online (Sandbox Code Playgroud) 如何在IntelliJ IDEA中向项目添加外部库,以便在构建工件时它仍然可以访问库中的类?
我从Project Structure创建了一个新的Jar工件,然后将外部JAR添加到Libraries,然后在Modules List中检查它,最后将它添加到Artifact的Output中.这些都不起作用.当我构建并尝试运行我的应用程序时,它会抛出一个错误:
Exception in thread "main" java.lang.NoClassDefFoundError: <path of the class trying to use>
我错过了什么,或者我完全错了?
当从我的 Kotlin 代码创建一个 jar 并运行它时,它说“没有主清单属性”。查看 manifest.mf 时,它包含以下内容:
Manifest-Version: 1.0
Run Code Online (Sandbox Code Playgroud)
查看源文件中的文件时,它具有以下内容:
Manifest-Version: 1.0
Main-Class: MyMainClass
Run Code Online (Sandbox Code Playgroud)
手动将源清单复制到 jar 时,它运行完美。
build ×2
java ×2
kotlin ×2
dependencies ×1
gradle ×1
jvm ×1
manifest ×1
manifest.mf ×1
maven ×1