Issue
I created a very simple web server using com.sun.net.httpserver.HttpServer
bundled in jdk11,
and I do not have any dependencies so I don't even want to create a pom or gradle build file.
In Google Cloud Run, I can do it with a simple Dockerfile compiling *.java and just execute it.
1 java source file & 1 Dockerfile do the job like below:
import java.io.IOException;
import java.net.InetSocketAddress;
import com.sun.net.httpserver.HttpServer;
public class Main {
public static void main(String[] args) throws IOException {
HttpServer server = HttpServer.create(new InetSocketAddress(8080), 0);
server.createContext("/", exchange -> {
byte[] result = "Hello World!".getBytes();
exchange.sendResponseHeaders(200, result.length);
exchange.getResponseBody().write(result);
});
server.start();
}
}
FROM openjdk:11-slim
COPY Main.java /home/Main.java
WORKDIR /home/
RUN javac Main.java
ENTRYPOINT ["java", "Main"]
Is it possible to achieve in App Engine?
Solution
You can build an executable JAR locally, and deploy that.
Please refer to more details on the link below: https://cloud.google.com/appengine/docs/standard/java11/testing-and-deploying-your-app#other_deployment_options
Answered By - Gourav B
Answer Checked By - Mildred Charles (JavaFixing Admin)