1*e07d83d3SAndroid Build Coastguard Worker# Hello World Example using Servlets 2*e07d83d3SAndroid Build Coastguard Worker 3*e07d83d3SAndroid Build Coastguard WorkerThis example uses Java Servlets instead of Netty for the gRPC server. This example requires `grpc-java` 4*e07d83d3SAndroid Build Coastguard Workerand `protoc-gen-grpc-java` to already be built. You are strongly encouraged to check out a git release 5*e07d83d3SAndroid Build Coastguard Workertag, since these builds will already be available. 6*e07d83d3SAndroid Build Coastguard Worker 7*e07d83d3SAndroid Build Coastguard Worker```bash 8*e07d83d3SAndroid Build Coastguard Workergit checkout v<major>.<minor>.<patch> 9*e07d83d3SAndroid Build Coastguard Worker``` 10*e07d83d3SAndroid Build Coastguard WorkerOtherwise, you must follow [COMPILING](../../COMPILING.md). 11*e07d83d3SAndroid Build Coastguard Worker 12*e07d83d3SAndroid Build Coastguard WorkerTo build the example, 13*e07d83d3SAndroid Build Coastguard Worker 14*e07d83d3SAndroid Build Coastguard Worker1. **[Install gRPC Java library SNAPSHOT locally, including code generation plugin](../../COMPILING.md) (Only need this step for non-released versions, e.g. master HEAD).** 15*e07d83d3SAndroid Build Coastguard Worker 16*e07d83d3SAndroid Build Coastguard Worker2. In this directory, build the war file 17*e07d83d3SAndroid Build Coastguard Worker```bash 18*e07d83d3SAndroid Build Coastguard Worker$ ../gradlew war 19*e07d83d3SAndroid Build Coastguard Worker``` 20*e07d83d3SAndroid Build Coastguard Worker 21*e07d83d3SAndroid Build Coastguard WorkerTo run this, deploy the war, now found in `build/libs/example-servlet.war` to your choice of servlet 22*e07d83d3SAndroid Build Coastguard Workercontainer. Note that this container must support the Servlet 4.0 spec, for this particular example must 23*e07d83d3SAndroid Build Coastguard Workeruse `javax.servlet` packages instead of the more modern `jakarta.servlet`, though there is a `grpc-servlet-jakarta` 24*e07d83d3SAndroid Build Coastguard Workerartifact that can be used for Jakarta support. Be sure to enable http/2 support in the servlet container, 25*e07d83d3SAndroid Build Coastguard Workeror clients will not be able to connect. 26*e07d83d3SAndroid Build Coastguard Worker 27*e07d83d3SAndroid Build Coastguard WorkerTo test that this is working properly, build the HelloWorldClient example and direct it to connect to your 28*e07d83d3SAndroid Build Coastguard Workerhttp/2 server. From the parent directory: 29*e07d83d3SAndroid Build Coastguard Worker 30*e07d83d3SAndroid Build Coastguard Worker1. Build the executables: 31*e07d83d3SAndroid Build Coastguard Worker```bash 32*e07d83d3SAndroid Build Coastguard Worker$ ../gradlew installDist 33*e07d83d3SAndroid Build Coastguard Worker``` 34*e07d83d3SAndroid Build Coastguard Worker2. Run the client app, specifying the name to say hello to and the server's address: 35*e07d83d3SAndroid Build Coastguard Worker```bash 36*e07d83d3SAndroid Build Coastguard Worker$ ./build/install/examples/bin/hello-world-client World localhost:8080 37*e07d83d3SAndroid Build Coastguard Worker```