diff options
-rw-r--r-- | build.gradle | 9 | ||||
-rw-r--r-- | server/build.gradle | 27 | ||||
-rw-r--r-- | server/src/ch/asynk/rustanddust/server/Server.java | 37 | ||||
-rw-r--r-- | settings.gradle | 2 |
4 files changed, 74 insertions, 1 deletions
diff --git a/build.gradle b/build.gradle index bd67a0a..24ada65 100644 --- a/build.gradle +++ b/build.gradle @@ -77,6 +77,15 @@ project(":core") { } } +project(":server") { + apply plugin: "java" + + + dependencies { + compile project(":core") + } +} + task ctags(type: Exec) { executable "ctags" args "-R", "--language-force=java", "-f.tags", "core/src/" diff --git a/server/build.gradle b/server/build.gradle new file mode 100644 index 0000000..d2c6481 --- /dev/null +++ b/server/build.gradle @@ -0,0 +1,27 @@ +apply plugin: "java" + +sourceCompatibility = 1.7 +sourceSets.main.java.srcDirs = [ "src/" ] + +project.ext.mainClassName = "ch.asynk.rustanddust.server.Server" + +task run(dependsOn: classes, type: JavaExec) { + main = project.mainClassName + classpath = sourceSets.main.runtimeClasspath + standardInput = System.in + /* workingDir = project.assetsDir */ + ignoreExitValue = true +} + +task dist(type: Jar) { + from files(sourceSets.main.output.classesDir) + from files(sourceSets.main.output.resourcesDir) + from {configurations.compile.collect {zipTree(it)}} + /* from files(project.assetsDir); */ + + manifest { + attributes 'Main-Class': project.mainClassName + } +} + +dist.dependsOn classes diff --git a/server/src/ch/asynk/rustanddust/server/Server.java b/server/src/ch/asynk/rustanddust/server/Server.java new file mode 100644 index 0000000..4a2000c --- /dev/null +++ b/server/src/ch/asynk/rustanddust/server/Server.java @@ -0,0 +1,37 @@ +package ch.asynk.rustanddust.server; + +import java.io.IOException; +import java.io.OutputStream; +import java.net.InetSocketAddress; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; +import com.sun.net.httpserver.HttpServer; + +public class Server +{ + + public static void main(String[] args) throws Exception + { + HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0); + server.createContext("/test", new MyHandler()); + server.setExecutor(null); + server.start(); + // System.exit(0); + } + + static class MyHandler implements HttpHandler + { + @Override + public void handle(HttpExchange t) throws IOException + { + System.err.print("answering ..."); + String response = "This is the response"; + t.sendResponseHeaders(200, response.length()); + OutputStream os = t.getResponseBody(); + os.write(response.getBytes()); + os.close(); + System.err.print("done."); + } + } +} diff --git a/settings.gradle b/settings.gradle index 13eeafe..d729d0d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include 'desktop', 'android', 'core', 'assets' +include 'desktop', 'android', 'core', 'assets', 'server' |