vscode-kotlin icon indicating copy to clipboard operation
vscode-kotlin copied to clipboard

What to specify for mainClass when there is none?

Open HubKing opened this issue 3 years ago • 4 comments

Motivation

It would be helpful if the tooltip showed what to do when there is no main class.

Description

I created a new directory, opened it, and created "main.kt"

fun main(args: Array<String>) {
	println("hello?");
}

Then, I selected the default "kotlin" launch script, and it had "mainClass" setting. But my file has no main class. Tried "mainClass": "${workspaceFolder}\\main.kt", but it did not work.

Alternatives considered

Creating a class. But that's cumbersome.

HubKing avatar Jan 20 '22 20:01 HubKing

The fully qualified name of your main class (usually your filename in PascalCase postfixed with Kt).

Could you try MainKt?

fwcd avatar Jan 25 '22 14:01 fwcd

Note that debugging support outside of Maven/Gradle projects is still pretty limited, you may have to manually compile with kotlinc.

fwcd avatar Jan 25 '22 14:01 fwcd

Same problem. I also tried MainKt, and compiled with kotlinc to a MainKt.class file.

[INFO] main      Connected to client
[INFO] async1    Could not resolve kotlin-stdlib using Maven: Cannot invoke "java.nio.file.Path.getFileSystem()" because "path" is null
[INFO] async1    Successfully resolved kotlin-stdlib using Gradle
[INFO] async1    Starting JVM debug session with main class MainKt
Error: Could not find or load main class MainKt
Caused by: java.lang.ClassNotFoundException: MainKt
[INFO] eventBus  Sent exit event
[INFO] async0    Exiting JDI session

This is also not a Gradle project, even though Gradle is installed on the system.

marcus-wishes avatar Apr 02 '23 16:04 marcus-wishes

Same issue here! No matter what I try, compiling THEN launching still cannot find the main class

sam20908 avatar Nov 18 '23 23:11 sam20908