-
-
Save brennie/0110199ca5d6c5b7e1c7f966f68d558c to your computer and use it in GitHub Desktop.
Sponge Plugin Issues
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins { | |
id 'com.github.johnrengelman.shadow' version '2.0.2' | |
id 'java' | |
} | |
repositories { | |
mavenCentral() | |
maven { | |
name = 'sponge' | |
url = 'https://repo.spongepowered.org/maven' | |
} | |
} | |
group = 'ca.brennie' | |
version = '0.1.0-SNAPSHOT' | |
description = 'An HTTP JSON API' | |
dependencies { | |
compileOnly 'org.spongepowered:spongeapi:7.0.0' | |
implementation 'com.sparkjava:spark-core:2.7.1' | |
implementation 'javax.servlet:javax.servlet-api:3.1.0' | |
} | |
jar { | |
onlyIf { false } | |
} | |
shadowJar { | |
dependencies { | |
exclude dependency("org.slf4j.*:") | |
// uncommenting this fixes the issue? | |
// relocate 'javax.servlet', 'ca.brennie.vendor.javax.servlet' | |
exclude '/about.html' | |
exclude '/jetty-dir.css' | |
} | |
} | |
build.dependsOn shadowJar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ca.brennie.mchttpapi; | |
import org.spongepowered.api.event.Listener; | |
import org.spongepowered.api.event.game.state.GameStartedServerEvent; | |
import org.spongepowered.api.event.game.state.GameStoppingServerEvent; | |
import org.spongepowered.api.plugin.Plugin; | |
import static spark.Spark.*; | |
@Plugin( | |
id = "mchttpapi", | |
version = "0.1.0", | |
name = "MC HTTP API", | |
description = "An HTTP API for interacting with a Minecraft server." | |
) | |
public class HttpApiPlugin { | |
@Listener | |
public void onServerStart(final GameStartedServerEvent event) { | |
// Uncommenting the following also fixes the issue. | |
// ClassLoader loader = HttpApiPlugin.class.getClassLoader(); | |
// try { | |
// loader.loadClass("javax/servlet/ServletContext"); | |
// } catch (final ClassNotFoundException e) {} | |
get("/", (req, rsp) -> "Hello, world"); | |
} | |
@Listener | |
public void onServerStopping(final GameStoppingServerEvent event) { | |
stop(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment