如何最好的方式来接收信息引用从minecraft插件?也许使用简单的http servlet,但如何启动他没有Tomcat?或者,也许,更好地使用websockets?
我正在创建一个项目使用插件“我的世界”像龙头插件,并尝试添加Spring Boot 网页启动器,但我不知道如何连接到插件他.
我已经添加了依赖项并更改插件:pom.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sniklz</groupId>
<artifactId>snikkzPlugin</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>SnikkzPlugin</name>
<description>asdasd</description>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>papermc-repo</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.18.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>3.0.1</version>
</dependency>
</dependencies>
</project>
SniklzPlugin.class:
package com.sniklz.snikkzplugin;
import org.bukkit.plugin.java.JavaPlugin;
public final class SnikkzPlugin extends JavaPlugin {
@Override
public void onEnable() {
// Plugin startup logic
new Thread(() -> {
SniklzPluginApp.start();
}).start();
}
@Override
public void onDisable() {
// Plugin shutdown logic
}
}
sniklzPluginApp.class:
package com.sniklz.snikkzplugin;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class SniklzPluginApp {
public static void start() {
SpringApplication.run(SniklzPluginApp.class);
}
}
控制器-〉第一个控制器类:
package com.sniklz.snikkzplugin.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/home")
public class FirstContoller {
@GetMapping
public String homeController() {
System.out.println("Hello World");
return "Hello world";
}
}
但是当我构建插件并从服务器启动它时,我得到这个错误:
Exception in thread "Thread-6" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
[09:02:43 WARN]: at snikkzPlugin-1.0-SNAPSHOT.jar//com.sniklz.snikkzplugin.SniklzPluginApp.start(SniklzPluginApp.java:14)
[09:02:43 WARN]: at snikkzPlugin-1.0-SNAPSHOT.jar//com.sniklz.snikkzplugin.SnikkzPlugin.lambda$onEnable$0(SnikkzPlugin.java:11)
[09:02:43 WARN]: at java.base/java.lang.Thread.run(Thread.java:833)
[09:02:43 WARN]: Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
[09:02:43 WARN]: at org.bukkit.plugin.java.PluginClassLoader.loadClass0(PluginClassLoader.java:151)
[09:02:43 WARN]: at org.bukkit.plugin.java.PluginClassLoader.loadClass(PluginClassLoader.java:103)
[09:02:43 WARN]: at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
1条答案
按热度按时间a11xaf1n1#
这个问题是因为你的插件没有spring代码。要解决这个问题,你应该include dependencies as jar。
您还可以在the class loader中添加一罐Spring。
最后,您可以为单线启动器执行
new Thread(SniklzPluginApp::start).start();