我正在尝试使用 undertow.io API启动一个简单的api服务器。这是我的启动代码。
this.server = Undertow.builder().addHttpListener(this.port, this.host).setHandler(new HttpHandler() {
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
exchange.getResponseSender().send("Hello World");
}
}).build();
this.server.start();
我会得到这个错误:
[22:26:46] [Server thread/ERROR]: Error occurred while enabling MWS v1.0-SNAPSHOT (Is it up to date?)
java.lang.ExceptionInInitializerError
at io.undertow.Undertow.start(Undertow.java:113) ~[?:?]
at me.ripes.mws.server.ApiServer.startServer(ApiServer.java:30) ~[?:?]
at me.ripes.mws.MWS.onEnable(MWS.java:20) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:271) ~[spigot-1.11.2.jar:git-Spigot-d276ab1-1f6c04c]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337) [spigot-1.11.2.jar:git-Spigot-d276ab1-1f6c04c]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot-1.11.2.jar:git-Spigot-d276ab1-1f6c04c]
at org.bukkit.craftbukkit.v1_11_R1.CraftServer.enablePlugin(CraftServer.java:376) [spigot-1.11.2.jar:git-Spigot-d276ab1-1f6c04c]
at org.bukkit.craftbukkit.v1_11_R1.CraftServer.enablePlugins(CraftServer.java:326) [spigot-1.11.2.jar:git-Spigot-d276ab1-1f6c04c]
at org.bukkit.craftbukkit.v1_11_R1.CraftServer.reload(CraftServer.java:750) [spigot-1.11.2.jar:git-Spigot-d276ab1-1f6c04c]
at org.bukkit.Bukkit.reload(Bukkit.java:540) [spigot-1.11.2.jar:git-Spigot-d276ab1-1f6c04c]
at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [spigot-1.11.2.jar:git-Spigot-d276ab1-1f6c04c]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [spigot-1.11.2.jar:git-Spigot-d276ab1-1f6c04c]
at org.bukkit.craftbukkit.v1_11_R1.CraftServer.dispatchCommand(CraftServer.java:650) [spigot-1.11.2.jar:git-Spigot-d276ab1-1f6c04c]
at org.bukkit.craftbukkit.v1_11_R1.CraftServer.dispatchServerCommand(CraftServer.java:636) [spigot-1.11.2.jar:git-Spigot-d276ab1-1f6c04c]
at net.minecraft.server.v1_11_R1.DedicatedServer.aM(DedicatedServer.java:437) [spigot-1.11.2.jar:git-Spigot-d276ab1-1f6c04c]
at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:400) [spigot-1.11.2.jar:git-Spigot-d276ab1-1f6c04c]
at net.minecraft.server.v1_11_R1.MinecraftServer.C(MinecraftServer.java:678) [spigot-1.11.2.jar:git-Spigot-d276ab1-1f6c04c]
at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:576) [spigot-1.11.2.jar:git-Spigot-d276ab1-1f6c04c]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_131]
Caused by: java.lang.IllegalArgumentException: Invalid logger interface io.undertow.UndertowLogger (implementation not found in org.bukkit.plugin.java.PluginClassLoader@12cb152a)
at org.jboss.logging.Logger$1.run(Logger.java:2556) ~[?:?]
at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_131]
at org.jboss.logging.Logger.getMessageLogger(Logger.java:2529) ~[?:?]
at org.jboss.logging.Logger.getMessageLogger(Logger.java:2516) ~[?:?]
at io.undertow.UndertowLogger.<clinit>(UndertowLogger.java:59) ~[?:?]
... 19 more
我认为这是暗流记录器的问题,但我不知道如何解决它。 请帮我:)
您的堆栈跟踪包含很多以下内容:~[?:?]。如果您在 jar 上运行 proguard 以缩小和混淆,则可能会删除您需要的记录器接口。禁用保护,然后重试。
您是否使用了正确的依赖项?我使用了与官方网站中提到的相同的依赖项,它在 Java 1.8 下对我有用。
你好世界服务器.java
package undertow;
import io.undertow.Undertow;
import io.undertow.server.HttpHandler;
import io.undertow.server.HttpServerExchange;
import io.undertow.util.Headers;
public class HelloWorldServer {
public static void main(final String[] args) {
HelloWorldServer helloWorldServer = new HelloWorldServer();
helloWorldServer.initiateServer();
}
private void initiateServer() {
this.server = Undertow.builder().addHttpListener(this.port, this.host).setHandler(new HttpHandler() {
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
exchange.getResponseSender().send("Hello World 312");
}
}).build();
this.server.start();
}
Undertow server = null;
int port= 8080;
String host = "localhost";
}
绒球.xml
<dependencies>
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-core</artifactId>
<version>1.4.12.Final</version>
</dependency>
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-servlet</artifactId>
<version>1.4.12.Final</version>
</dependency>
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-websockets-jsr</artifactId>
<version>1.4.12.Final</version>
</dependency>
</dependencies>
控制台输出
Jul 11, 2017 10:45:33 PM org.xnio.Xnio <clinit>
INFO: XNIO version 3.3.6.Final
Jul 11, 2017 10:45:33 PM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.3.6.Final
本地主机:8080打印"你好世界312">
Caused by: java.lang.IllegalArgumentException: Invalid logger interface io.undertow.UndertowLogger (implementation not found in org.bukkit.plugin.java.PluginClassLoader@12cb152a)
at org.jboss.logging.Logger$1.run(Logger.java:2556) ~[?:?]
io.undertow.UndertowLogger
是一个界面,它使用jboss.logging
注释之一进行注释。编译接口时,会执行注释处理器,这将生成记录器实现。
错误消息意味着,在运行时,JBoss 记录器无法加载实现类。
如果有问题的类是由您构建的,请检查在构建期间是否正在运行注释处理器。Maven有时会发疯并拒绝运行注释处理器。如果是这样,mvn clean
通常会解决这个问题。
如果该类由第三方提供,则可能缺少一些依赖项。