一个愚蠢的问题:到底应该如何调试和启动插件?
-
@diyigemt 哦豁完蛋,那这转了一大圈我还是没找到java在程序内实时加载的办法。。。
-
@orisland 欸启动调试可以用runMiraiKt这个gradle任务在idea里调试插件吧?如果我没理解错
https://eritque-arcus.tech/2020/12/28/Mirai-qq机器人框架kotlin_java教程/ -
@nambers 我的项目里,根本没有这个task,也没有test文件(向上翻可得根目录截图结构)。我的这个plugin是插件直接自动生成的,什么都没有,我尝试复制其他项目的文件,结果其他项目的插件启动全是kotlin,我的是java,用不了,我现在不知道怎么处理。
-
@orisland 试一下我这个看看?https://github.com/Nambers/mirai_plugin_example
java文件夹就是java的 -
@nambers 我自己改的文件,也是这个报错……
plugin是我插件随便写的名字.Exception in thread "main" java.lang.NoClassDefFoundError: net/mamoe/mirai/console/MiraiConsoleImplementation at java.base/java.lang.ClassLoader.defineClass1(Native Method) at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017) at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174) at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:800) at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:698) at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:621) at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:579) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) at net.mamoe.mirai.console.terminal.MiraiConsoleTerminalLoader.startAsDaemon$default(MiraiConsoleTerminalLoader.kt:152) at RunConsoleKt.main(RunConsole.kt:10) at RunConsoleKt$$$main.invoke(Unknown Source) at kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsJvmKt$createCoroutineUnintercepted$$inlined$createCoroutineFromSuspendFunction$IntrinsicsKt__IntrinsicsJvmKt$1.invokeSuspend(IntrinsicsJvm.kt:205) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlin.coroutines.ContinuationKt.startCoroutine(Continuation.kt:115) at kotlin.coroutines.jvm.internal.RunSuspendKt.runSuspend(RunSuspend.kt:19) at RunConsoleKt.main(RunConsole.kt) Caused by: java.lang.ClassNotFoundException: net.mamoe.mirai.console.MiraiConsoleImplementation at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) ... 17 more
-
@orisland 我刚刚试了下,我本身跑是没什么问题,你plugin那个java文件下的主类名称也是plugin吗,就继承javaPlugin的类
-
gradle没配好吧,环境不全?
-
@nambers
是的,这是idea的mirai插件自动创建的,除了插件基本信息外我没有做任何修改。package com.orisland; import jdk.nashorn.internal.ir.Terminal; import net.mamoe.mirai.Bot; import net.mamoe.mirai.BotFactory; import net.mamoe.mirai.console.MiraiConsole; import net.mamoe.mirai.console.plugin.jvm.JavaPlugin; import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescriptionBuilder; public final class Plugin extends JavaPlugin { public static final Plugin INSTANCE = new Plugin(); private Plugin() { super(new JvmPluginDescriptionBuilder("com.orisland.plugin", "1.0-SNAPSHOT") .name("Orisland's plugin") .info("what???") .author("orisland") .build()); } @Override public void onEnable() { getLogger().info("Plugin loaded!"); } }
-
@colter23 应该不是这个问题吧,而且不全我也不知道怎么补,我创建了两次,都不行:drooling_face: 麻了,找不出原因,插件也没法写:dizzy_face:
-
@orisland 那很怪,我和你代码基本一样,你检查下gradle的mirai版本?
id("net.mamoe.mirai-console") version "2.6.4"
然后把resource目录下的META-IMF下的
net.mamoe.mirai.console.plugin.jvm.JvmPlugin
文件内容改成你的类包名,不过应该不是这个的问题 -
@nambers
是不是dependencies出问题了=。=我感觉好像我动过这部分:face_with_head_bandage:plugins { val kotlinVersion = "1.4.30" kotlin("jvm") version kotlinVersion kotlin("plugin.serialization") version kotlinVersion id("net.mamoe.mirai-console") version "2.6.4" } group = "com.orisland" version = "1.0-SNAPSHOT" repositories { maven("https://maven.aliyun.com/repository/public") mavenCentral() } dependencies { // 开发时使用 mirai-core-api,运行时提供 mirai-core api("net.mamoe:mirai-core-api:2.6.4") api("net.mamoe:mirai-console-terminal:2.6.4") runtimeOnly("net.mamoe:mirai-core:2.6.4") // 可以简单地只添加 api("net.mamoe:mirai-core:2.6.1") }
-
dependencies 里的可以删了 上面已经使用了mirai-console插件了
-
@orisland 如果写mriai-console不用mirai-core的东西吧,删掉看看,也可能冲突了
-
@colter23 在 一个愚蠢的问题:到底应该如何调试和启动插件? 中说:
dependencies 里的可以删了 上面已经使用了mirai-console插件了
问题依旧,我将错误项目直接传出来了,大佬们如果有空的话可以看看链接
为了可以实时调试已经搞了一下午了:dizzy_face: :dizzy_face:"/Applications/IntelliJ IDEA.app/Contents/jbr/Contents/Home/bin/java" -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=53560:/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8 -classpath /Users/zhaolong/IdeaProjects/SetuPlus/build/classes/java/main:/Users/zhaolong/IdeaProjects/SetuPlus/build/classes/kotlin/main:/Users/zhaolong/IdeaProjects/SetuPlus/build/resources/main:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/net.mamoe/mirai-console-terminal/2.6.4/834ce5943058277e8cf6ca075fec1d62eac49edb/mirai-console-terminal-2.6.4.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.4.30/aeecfab2e6acbcb80fc6628e8882c98cbbd819cf/kotlin-stdlib-jdk8-1.4.30.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/net.mamoe/mirai-core-api-jvm/2.6.4/9bbe022d06623bc8b14d0a883e992db763b83cac/mirai-core-api-jvm-2.6.4.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.4.30/cd81ed90fd79e43f587bd384c2bc6d1aed0bfe31/kotlin-stdlib-jdk7-1.4.30.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.4.30/d10d1e10f47006ee08162dde039e38ac487de4ac/kotlin-stdlib-1.4.30.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-coroutines-jdk8/1.4.2/5fade60e503a55fc9d3af41b7190de1a84b14e3f/kotlinx-coroutines-jdk8-1.4.2.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/io.ktor/ktor-client-okhttp/1.5.1/f3ade3edfeb40c0c531bd31706ed1993e7d5d85f/ktor-client-okhttp-jvm-1.5.1.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-reflect/1.4.30/a9116fbe28a0514671787df95133f28e65fdac25/kotlin-reflect-1.4.30.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-serialization/1.4.30/96dbda4bf53b86a548421775d886fdb42ddcb37c/kotlin-serialization-1.4.30.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-coroutines-io-jvm/0.1.16/b2bcf3815337e34b598b9e9a579fe5ec0f8a3ab4/kotlinx-coroutines-io-jvm-0.1.16.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-io-jvm/0.1.16/121c7a446719b21f8f1275134d6073aa22b23121/kotlinx-io-jvm-0.1.16.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.4.30/bb9a3173350f55732416ee27956ea8f9b81f4dbb/kotlin-stdlib-common-1.4.30.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/com.squareup.okhttp3/okhttp/4.6.0/1885ec944e0a74e78359756e88ce656fd5a596d5/okhttp-4.6.0.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-api/1.7.30/b5a4b6d16ab13e34a88fae84c35cd5d68cac922c/slf4j-api-1.7.30.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/io.ktor/ktor-client-core-jvm/1.5.1/d232964dba7318a8aa131b498f58482303038ccd/ktor-client-core-jvm-1.5.1.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/io.ktor/ktor-network-jvm/1.5.1/f24b541c0a2f5ed4b860d27beb47e7729a5cfc62/ktor-network-jvm-1.5.1.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-gradle-plugin-api/1.4.30/a66fa6006e99b46025bc21653c2bf89316053fb5/kotlin-gradle-plugin-api-1.4.30.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-serialization-json-jvm/1.1.0/86c26030512eb057e02c9bfcfdfd9e2fbb82201/kotlinx-serialization-json-jvm-1.1.0.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-serialization-core-jvm/1.1.0/6a6d0b8e8a44c48e206e435d279b1773832f4f1b/kotlinx-serialization-core-jvm-1.1.0.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-coroutines-io/0.1.16/a148ebbf458bb8c787ded007a62a6f53324358e1/kotlinx-coroutines-io-0.1.16.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/atomicfu-common/0.14.1/323b5e62491623e6670ebe593af2ebfbf46cb210/atomicfu-common-0.14.1.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-io/0.1.16/c2bb49e5fa65eed71e1ea0dc12e78619296a01fd/kotlinx-io-0.1.16.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-coroutines-core-jvm/1.4.2/4b9c6b2de7cabfb2c9ad7a5c709b1ddb7bbfd2ad/kotlinx-coroutines-core-jvm-1.4.2.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/com.squareup.okio/okio/2.6.0/f06923d428f3c8e6f571043ec29a45d0cd9d2bf/okio-jvm-2.6.0.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/io.ktor/ktor-http-cio-jvm/1.5.1/b41829b9e7e354c9a6e55ee888c7d83b53a51984/ktor-http-cio-jvm-1.5.1.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/io.ktor/ktor-http-jvm/1.5.1/8347ad9b7ac34137f162427e23fa4145e96f8262/ktor-http-jvm-1.5.1.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/io.ktor/ktor-utils-jvm/1.5.1/9763b731d7017c5258a65a9d6f871a7a91ad5a34/ktor-utils-jvm-1.5.1.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/io.ktor/ktor-io-jvm/1.5.1/a6170780ba77e2cd7dcd94e63e4649c98516292d/ktor-io-jvm-1.5.1.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/net.mamoe/mirai-core-jvm/2.6.4/c96ed94bc608473bfecd3a173f223b73e409f482/mirai-core-jvm-2.6.4.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.jline/jline/3.15.0/6c8d38639ac26de5ccb5bed947ce2fd40b7e2269/jline-3.15.0.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.fusesource.jansi/jansi/1.18/d9205bbcd4b5f9cd1effe752d18f73bd942d783f/jansi-1.18.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-test-junit5/1.4.30/4ec1973ada0eabec38e9679cb0568423ed1c3790/kotlin-test-junit5-1.4.30.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.junit.jupiter/junit-jupiter-engine/5.4.2/4d10922ce4d9c4e22cef8ff5386cb273b9f12281/junit-jupiter-engine-5.4.2.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.junit.jupiter/junit-jupiter-api/5.4.2/665d1c0daecb26c6210c872768000b417e7e52b6/junit-jupiter-api-5.4.2.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.bouncycastle/bcprov-jdk15on/1.64/1467dac1b787b5ad2a18201c0c281df69882259e/bcprov-jdk15on-1.64.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.jetbrains/annotations/19.0.0/efbff6752f67a7c9de3e4251c086a88e23591dfd/annotations-19.0.0.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/net.mamoe/mirai-core-utils-jvm/2.6.4/67f768fd99efdacbc1d24592283801db43893af/mirai-core-utils-jvm-2.6.4.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-serialization-protobuf-jvm/1.1.0/a2c675697ad328d1a5293660dd9e1112e7a7ef17/kotlinx-serialization-protobuf-jvm-1.1.0.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-test/1.4.30/a8c0e21fda17f61a6de193e16dd414683cf9dcb0/kotlin-test-1.4.30.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-test-annotations-common/1.4.30/e77a76b23fc3007baf57a9d3354fdd318fe1fa88/kotlin-test-annotations-common-1.4.30.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.junit.platform/junit-platform-engine/1.4.2/52b70561f65bb397b054876f2d8c6f30b06c3581/junit-platform-engine-1.4.2.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.apiguardian/apiguardian-api/1.0.0/3ef5276905e36f4d8055fe3cb0bdcc7503ffc85d/apiguardian-api-1.0.0.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.junit.platform/junit-platform-commons/1.4.2/37993dc807ca253aa347be8968a0ae7b70642dbc/junit-platform-commons-1.4.2.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.opentest4j/opentest4j/1.1.1/efd9f971e91074491ea55b19f67b13470cf4fcdd/opentest4j-1.1.1.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/net.mamoe/kotlin-jvm-blocking-bridge-jvm/1.10.3/8291d6bffb195cba40873751e57cd38c88b3c392/kotlin-jvm-blocking-bridge-jvm-1.10.3.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/atomicfu-jvm/0.15.1/6874562ba1fc4e1448a42d0c5286b558e409aa68/atomicfu-jvm-0.15.1.jar:/Users/zhaolong/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-test-common/1.4.30/823ed87441680d1334a1f0d23781c0089e16c0a6/kotlin-test-common-1.4.30.jar RunConsoleKt Exception in thread "main" java.lang.NoClassDefFoundError: net/mamoe/mirai/console/MiraiConsoleImplementation at java.base/java.lang.ClassLoader.defineClass1(Native Method) at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017) at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174) at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:800) at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:698) at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:621) at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:579) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) at net.mamoe.mirai.console.terminal.MiraiConsoleTerminalLoader.startAsDaemon$default(MiraiConsoleTerminalLoader.kt:152) at RunConsoleKt.main(RunConsole.kt:10) at RunConsoleKt$$$main.invoke(Unknown Source) at kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsJvmKt$createCoroutineUnintercepted$$inlined$createCoroutineFromSuspendFunction$IntrinsicsKt__IntrinsicsJvmKt$1.invokeSuspend(IntrinsicsJvm.kt:205) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlin.coroutines.ContinuationKt.startCoroutine(Continuation.kt:115) at kotlin.coroutines.jvm.internal.RunSuspendKt.runSuspend(RunSuspend.kt:19) at RunConsoleKt.main(RunConsole.kt) Caused by: java.lang.ClassNotFoundException: net.mamoe.mirai.console.MiraiConsoleImplementation at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) ... 17 more Process finished with exit code 1
-
@orisland 可能是因为你test.java的位置不在test模块里,你可以去试一下,就按照我的项目构造,或者干脆把你代码复制过去用看看,我明天开下你发的看看
-
请参考 https://github.com/Him188/mirai-console-example-plugin/blob/master/src/test/kotlin/RunConsole.kt 在 test 中添加一个入口点
然后 IDEA 创建项目没 debug 入口点的问题可以在 https://github.com/mamoe/mirai-console 发起一个新的 issue -
@orisland 在 一个愚蠢的问题:到底应该如何调试和启动插件? 中说:
@nambers 我自己改的文件,也是这个报错……
plugin是我插件随便写的名字.Exception in thread "main" java.lang.NoClassDefFoundError: net/mamoe/mirai/console/MiraiConsoleImplementation at java.base/java.lang.ClassLoader.defineClass1(Native Method)
你的
RunConsole.kt
需要放在test
源集里面, 主源集(main
) 是不包含运行时的 -
@orisland 没有 test 源集文件夹就自己创建,
右键 / new / new Folder
在 IDEA 中是会有提示的 -
@nambers 我clone了佬的项目,ok已经可以了,看来启动文件放错位置的问题.
-
@karlatemp 在 一个愚蠢的问题:到底应该如何调试和启动插件? 中说:
@orisland 在 一个愚蠢的问题:到底应该如何调试和启动插件? 中说:
@nambers 我自己改的文件,也是这个报错……
plugin是我插件随便写的名字.Exception in thread "main" java.lang.NoClassDefFoundError: net/mamoe/mirai/console/MiraiConsoleImplementation at java.base/java.lang.ClassLoader.defineClass1(Native Method)
你的
RunConsole.kt
需要放在test
源集里面, 主源集(main
) 是不包含运行时的get,目前已经基本确定是这个问题,感谢佬的解答:flushed: