This application uses the Google Cloud Logging Client Libraries and can be compiled with Native Image Native Image.
You will need to follow these prerequisite steps in order to run the samples:
-
If you have not already, create a Google Cloud Platform Project.
-
Install the Google Cloud SDK which will allow you to run the sample with your project's credentials.
Once installed, log in with Application Default Credentials using the following command:
gcloud auth application-default loginNote: Authenticating with Application Default Credentials is convenient to use during development, but we recommend alternate methods of authentication during production use.
-
Install the native image compiler.
You can follow the official installation instructions. After following the instructions, ensure that you install the native image extension installed by running:
gu install native-imageOnce you finish following the instructions, verify that the default version of Java is set to the correct version by running
java -versionin a terminal.You will see something similar to the below output:
$ java -version openjdk version "17.0.3" 2022-04-19 OpenJDK Runtime Environment GraalVM CE 22.1.0 (build 17.0.3+7-jvmci-22.1-b06) OpenJDK 64-Bit Server VM GraalVM CE 22.1.0 (build 17.0.3+7-jvmci-22.1-b06, mixed mode, sharing) -
Enable the Logging APIs.
Navigate to this directory in a new terminal.
-
Compile the application using the native image Compiler. This step may take a few minutes.
mvn package -P native -DskipTests -
Run the application:
./target/native-image-sample -
The application will log a message to your local terminal and to Google Cloud Console.
Navigate to the Cloud Console Logs Viewer to view you logs and find the newly generated log entry in Cloud Console:
This is a log produced by Native Image.
In order to run the sample integration test as a native image, call the following command:
mvn test -Pnative