A simple HTTP server that consists of a single executable and serves a folder from the machine. It may be useful when you need to open an HTML page or set of web resources in a browser, and they require an HTTP server to be opened correctly (pages making AJAX requests to local resources, Selenium reports, etc.).
This project uses Quarkus, the Supersonic Subatomic Java Framework. :)
If you want to learn more about Quarkus, please visit its website: https://quarkus.io/ .
- server # for default localhost:8080
- server 8081 # for localhost and port 8081
- server 0.0.0.0:8081 # for defining host and port to listen on
The server will start on port 8080 by default. However, Quarkus starts listening on another
HTTP port, which is required for some system purposes. I couldn't find any way to disable it
and all I managed to do so far is to make Quarkus pick some random port by setting
quarkus.http.port=0
(see https://quarkus.io/guides/http-reference for details). Maybe there
can exist any interference with the server port, but I don't think it can happen in 99.999999%
of all the cases.
You can run your application in dev mode that enables live coding using:
./mvnw compile quarkus:dev
The application can be packaged using:
./mvnw package
It produces the utils.cmd.httpServer-1.0.0-SNAPSHOT-runner.jar
file in the /target
directory.
Be aware that it’s not an über-jar as the dependencies are copied into the target/lib
directory.
If you want to build an über-jar, execute the following command:
./mvnw package -Dquarkus.package.type=uber-jar
The application is now runnable using java -jar target/utils.cmd.httpServer-1.0.0-SNAPSHOT-runner.jar
.
You can create a native executable using:
./mvnw package -Pnative
Or, if you don't have GraalVM installed, you can run the native executable build in a container using:
./mvnw package -Pnative -Dquarkus.native.container-build=true
You can then execute your native executable with: ./target/utils.cmd.httpServer-1.0.0-SNAPSHOT-runner
If you want to learn more about building native executables, please consult https://quarkus.io/guides/maven-tooling.html.
I used Windows 10 x64 VM. Reference for building native Quarkus images: https://quarkus.io/guides/building-native-image
Steps on Windows:
- Download and unpack GraalVM for Windows
- Download and install Visual Studio 2017 Visual C++ Build Tools (https://aka.ms/vs/15/release/vs_buildtools.exe)
- Set JAVA_HOME and GRAALVM_HOME to unpacked GraalVM folder
- Run
${GRAALVM_HOME}/bin/gu install native-image
- Add
${GRAALVM_HOME}/bin
to PATH - Add
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64
to PATH - Open cmd, go to the project folder
- Run
"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvars64"
- Run
mvnw clean install
- Run
mvnw package -Pnative