Code Monkey home page Code Monkey logo

gttp's Introduction

gttp - simple HTTP server in Groovy

Inspired by http://melix.github.io/blog/2019/03/simple-http-server-graal.html

Install Groovy

$ sdk install groovy 3.0.5

Install GraalVM 20.2 (JDK 11)

$ sdk install java 20.2.0.r11-grl

$ sdk use java 20.2.0.r11-grl

$ gu install native-image

Compile gttp

$ groovyc --compile-static gttp.groovy

Run gttp with native-image-agent

$ java -agentlib:native-image-agent=config-output-dir=conf/ -cp ".:$GROOVY_HOME/lib/groovy-3.0.5.jar" gttp 

Build native image

$ native-image --allow-incomplete-classpath \
  --report-unsupported-elements-at-runtime \
  --initialize-at-build-time \
  --initialize-at-run-time=org.codehaus.groovy.control.XStreamUtils \
  --no-fallback \
  --no-server \
  -H:ConfigurationFileDirectories=conf/ \
  -cp ".:$GROOVY_HOME/lib/groovy-3.0.5.jar" \ 
  gttp

Run gttp as a standalone executable file

$ ./gttp
Listening at http://localhost:8080/

Change default port

$ ./gttp 9000
Listening at http://localhost:9000/

Change default base directory to /tmp

$ ./gttp 9000 /tmp
Listening at http://localhost:9000/

Alternative: setup environment & build in a docker container

You can also use attached Dockerfile to install all required components, compile Groovy script to Java bytecode, and generate standalone executable file using native-image tool.

$ sh ./build-with-docker.sh

gttp's People

Contributors

wololock avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.