You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

IntelliJ无法运行Kotlin程序:不生成class文件但Maven打包正常

IntelliJ运行Kotlin程序报错:找不到主类net.kolotyluk.nima.advent.MainKt

我的Main.kt代码

package net.kolotyluk.nima.advent

fun main() {
    println("What's your name?")
}

命令行运行打包后的JAR文件正常

"C:\Program Files\Java\jdk-19\bin\java.exe" -Dfile.encoding=windows-1252 -Dsun.stdout.encoding=windows-1252 -Dsun.stderr.encoding=windows-1252 -jar C:\Users\ERIC\Documents\git\helidon-nima-example\advent\target\advent-1.0-SNAPSHOT.jar
What's your name?

Process finished with exit code 0

直接在IntelliJ中运行报错

"C:\Program Files\Java\jdk-19\bin\java.exe" --enable-preview "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2023.1\lib\idea_rt.jar=50405:C:\Program Files\JetBrains\IntelliJ IDEA 2023.1\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath C:\Users\ERIC\Documents\git\helidon-nima-example\advent\target\classes;... net.kolotyluk.nima.advent.MainKt
Error: Could not find or load main class net.kolotyluk.nima.advent.MainKt
Caused by: java.lang.ClassNotFoundException: net.kolotyluk.nima.advent.MainKt

Process finished with exit code 1

核心疑问

  • 发现target目录中不存在net.kolotyluk.nima.advent.MainKt对应的class文件,但打包后的JAR文件里却有这个类。
  • 第一次在IntelliJ中运行简单的Hello-World风格程序遇到此问题:为什么mvn clean package能正常构建出可运行的JAR,而IntelliJ却不生成对应的class文件?

内容的提问来源于stack exchange,提问作者Eric Kolotyluk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 13:22:41