已解决 界面机器人开发插件加载问题
-
大佬们,想问下
kotlin
根据MIrai-Core
和MIrai-Core-Api
开发PC界面机器人程序机器人提供插件接口,插件实现接口要如何被机器人加载进程序。
没写过这种,求大佬们教教XD -
Google Search:
Java Hot Loading
,Java ClassLoader
,Java load class from other jar
-
?请使用mirai- console
-
¿ 什么意思
-
@rainchan
我用了console后就出现ClassNotFoundException和NoClassDefFoundError,是我搞错了吗Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1862) at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1729) at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191) at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49) at javafx.event.Event.fireEvent(Event.java:198) at javafx.scene.Node.fireEvent(Node.java:8889) at javafx.scene.control.Button.fire(Button.java:203) at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:208) at com.sun.javafx.scene.control.inputmap.InputMap.handle(InputMap.java:274) at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:247) at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191) at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54) at javafx.event.Event.fireEvent(Event.java:198) at javafx.scene.Scene$MouseHandler.process(Scene.java:3856) at javafx.scene.Scene.processMouseEvent(Scene.java:1851) at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2584) at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:409) at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:299) at java.base/java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:447) at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:412) at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:446) at com.sun.glass.ui.View.handleMouseEvent(View.java:556) at com.sun.glass.ui.View.notifyMouse(View.java:942) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174) at java.base/java.lang.Thread.run(Thread.java:829) Caused by: java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at com.sun.javafx.reflect.Trampoline.invoke(MethodUtil.java:76) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at com.sun.javafx.reflect.MethodUtil.invoke(MethodUtil.java:273) at com.sun.javafx.fxml.MethodHelper.invoke(MethodHelper.java:83) at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1857) ... 46 more Caused by: java.lang.NoClassDefFoundError: net/mamoe/mirai/console/MiraiConsole at com.hcyacg.miraiView.controller.LoginController.login(LoginController.kt:65) ... 58 more Caused by: java.lang.ClassNotFoundException: net.mamoe.mirai.console.MiraiConsole 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) ... 59 more 进程已结束,退出代码为 0
build.gradle
plugins { id 'java' id 'application' id 'org.jetbrains.kotlin.jvm' version '1.5.30-RC' id 'org.jetbrains.kotlin.plugin.serialization' version '1.5.30-RC' id 'org.openjfx.javafxplugin' version '0.0.10' id 'net.mamoe.mirai-console' version '2.7-RC' } group 'com.hcyacg' version '1.0-SNAPSHOT' repositories { mavenLocal() maven { url = "https://maven.aliyun.com/repository/gradle-plugin" } maven { url = "https://maven.aliyun.com/repository/public" } mavenCentral() } ext { junitVersion = '5.7.2' } sourceCompatibility = '11' targetCompatibility = '11' tasks.withType(JavaCompile) { options.encoding = 'UTF-8' } application { mainModule = 'com.hcyacg.miraiView' mainClass = 'com.hcyacg.miraiView.App' } [compileKotlin, compileTestKotlin].forEach { it.kotlinOptions { jvmTarget = '11' } } javafx { version = '11.0.2' modules = ['javafx.controls', 'javafx.fxml', 'javafx.web'] } dependencies { implementation('org.controlsfx:controlsfx:11.1.0') implementation('com.dlsc.formsfx:formsfx-core:11.4.2') // implementation('net.synedra:validatorfx:0.1.13') // {exclude(group: 'org.openjfx')} implementation('org.kordamp.ikonli:ikonli-javafx:12.2.0') implementation('org.kordamp.bootstrapfx:bootstrapfx-core:0.4.0') implementation('eu.hansolo:tilesfx:11.48') implementation("org.apache.commons:commons-lang3:3.12.0") var miraiVersion = "2.7-RC-dev-3" // api("net.mamoe:mirai-core-api:${miraiVersion}") // 编译代码使用 // runtimeOnly("net.mamoe:mirai-core:${miraiVersion}") // 运行时使用 // implementation("net.mamoe:mirai-console:${miraiVersion}") testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}") testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}") } test { useJUnitPlatform() } sourceSets { main.java.srcDirs = ['src/main/java'] main.kotlin.srcDirs = ['src/main/java', 'src/main/kotlin'] main.resources.srcDirs = ['src/main/resources'] }
val bot = MiraiConsole.addBot(username.text.toLong(),password.text.toString()) { this.redirectNetworkLogToFile(logFile) BotConfiguration.MiraiProtocol.ANDROID_PAD } runBlocking { bot.configuration.networkLoggerSupplier = { NetLogger() } GlobalEventChannel.subscribeAlways<MessageEvent> { event -> val record = Record( SimpleStringProperty(timeFormat.format(event.time)), SimpleStringProperty("INFO"), SimpleStringProperty("${event.subject}"), SimpleStringProperty(event.message.toString()) ) RecordController.cellData.add(record) } bot.login() }
-
@karlatemp
现在打算写一个基于Mirai
的桌面程序机器人,然后现在需要加载插件功能。加载插件我找了半天只有
console
里面提供了,但是引用console
的直接ClassNotFoundException
和NoClassDefFoundError
。除此之外要是实现加载插件功能不是就得提供接口,插件实现接口来开发吗,这里的问题是机器人主程序如何将插件注入到程序里
-
Google Search:
Java Hot Loading
,Java ClassLoader
,Java load class from other jar
-
你可以在mirai-compose的基础上来修改
-
qs 可以参考mirai-compose, 或者自己找console的对接插件的那一部分复刻一遍,如 https://github.com/mamoe/mirai-console/blob/master/backend/mirai-console/src/plugin/loader/PluginLoader.kt
-
@karlatemp 感谢,已通过反射完成插件加载
-
客户端还请保持低调 避免带来不必要的麻烦