Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 575 Vote(s) - 3.44 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IntelliJ IDEA: How to specify main class in Kotlin?

#1
I try to build a jar with Intellij Idea with Kotlin Gradle project.
Idea doesn't see my main class when I try to configure Artifact

here's my Gradle :

plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.3.60'
id 'application'
}
group 'org.vladdrummer'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
mavenCentral()
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin/'
}

jar {
manifest {
attributes 'Main-Class': 'MovieQuizBackendKt'
}
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
compile "com.sparkjava:spark-kotlin:1.0.0-alpha"
implementation 'com.google.code.gson:gson:2.8.2'
runtime 'mysql:mysql-connector-java:5.1.34'
testCompile group: 'junit', name: 'junit', version: '4.12'
}

compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}

Here's structure :

[![structure][1]][1]


Here's main class :

class MovieQuizBackend {

fun main(args: Array<String>) {
Server()
}
}

[1]:
Reply

#2
In Kotlin language entry point is not a method inside the class (a class with the `Kt` suffix in the name is generated automatically from a file). See [the documentation](

[To see links please register here]

).

Your code inside the `MovieQuizBackend.kt` file needs to be changed to the following:

```
fun main(args : Array<String>) {
Server()
}
```

Just remove the `class MovieQuizBackend {` and `}` at the end.

You can even omit `args` if you don't plan to pass any:

```
fun main() {
Server()
}
```

Another option is to use `@JvmStatic` annotation inside the `companion object`:

```
class MovieQuizBackend {
companion object {
@JvmStatic fun main(args : Array<String>) {
Server()
}
}
}
```

Note that this way the main class is named just `MovieQuizBackend` instead of `MovieQuizBackendKt`, so you will need to change it in `build.gradle`:

```
jar {
manifest {
attributes 'Main-Class': 'MovieQuizBackend'
}
}
```
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through