### Run Quickstart Sample Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/texttospeech/beta/README.md Execute the Quickstart sample to synthesize text to an output audio file using Maven. ```bash mvn exec:java -DQuickstart ``` -------------------------------- ### Run Quickstart with Maven Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/iam/api-client/README.md Execute the Quickstart sample after building the project. Replace placeholder values for projectId and member in the code before running. ```xml mvn exec:java ``` -------------------------------- ### Install Git, Java, and Maven Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/compute/error-reporting/README.md Update system packages and install Git, OpenJDK 8, and Maven on the compute instance. ```bash sudo apt-get update && sudo apt-get install git-core openjdk-8-jdk maven ``` -------------------------------- ### Start Cloud Datastore Emulator Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/appengine-java8/guestbook-cloud-datastore/README.md Start the Cloud Datastore emulator locally. Replace YOUR_PROJECT_ID_HERE with your Google Cloud project ID. ```bash gcloud beta emulators datastore start --project=YOUR_PROJECT_ID_HERE ``` -------------------------------- ### Analyze String Sentiment with Quickstart Sample Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/language/cloud-client/README.md Execute the compiled JAR file to run the quickstart sample, which analyzes a string for sentiment using the Natural Language API. ```bash java -jar target/language-google-cloud-samples-1.0.9-jar-with-dependencies.jar \ com.example.language.QuickstartSample ``` -------------------------------- ### Clone and Setup Sample App Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/appengine-java11/spanner/README.md Clone the sample repository and set up the necessary dependencies for the App Engine Java 11 sample. ```bash git clone https://github.com/GoogleCloudPlatform/java-docs-samples ``` ```bash cd java-docs-samples/appengine-java11/appengine-simple-jetty-main mvn install ``` -------------------------------- ### Create a Bucket using Quickstart Sample Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/storage/cloud-client/README.md Run the QuickstartSample Java application with Maven to create a new bucket. Provide the desired bucket name as an argument. ```bash mvn exec:java -Dexec.mainClass=com.example.storage.QuickstartSample \ -Dexec.args="my-bucket-name" ``` -------------------------------- ### Run Helloworld Locally with Gradle Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/flexible/java-8/helloworld/README.md Use this command to run the Helloworld sample locally using Gradle. If Gradle is not installed, use ./gradlew appengineRun. ```bash $ gradle jettyRun ``` ```bash ./gradlew appengineRun ``` -------------------------------- ### Copy Example Secrets File Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/auth/src/main/java/com/google/cloud/auth/samples/customcredentials/okta/README.md Copy the example secrets file to a new file for local configuration. Fill in Okta and Google Cloud credentials. Do not commit this file to version control. ```bash cp custom-credentials-okta-secrets.json.example custom-credentials-okta-secrets.json ``` -------------------------------- ### List Buckets with Default Credentials Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/auth/README.md Run an example that lists buckets using default application credentials. Ensure your environment is configured with appropriate credentials. ```bash mvn exec:java -Dexec.mainClass=com.google.cloud.auth.samples.AuthExample ``` -------------------------------- ### Install Dependency with Maven Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/appengine-java11/appengine-simple-jetty-main/README.md Installs the sample as a local dependency using Maven. ```bash mvn install ``` -------------------------------- ### Run Helloworld Locally with Maven Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/flexible/java-8/helloworld/README.md Use this command to run the Helloworld sample locally using Maven. Ensure you have Maven installed. ```bash $ mvn clean jetty:run-exploded ``` -------------------------------- ### Build and Run Monitoring Alerts Sample Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/monitoring/v3/README.md Installs dependencies and executes the command-line tool for managing alerts. Replace ` ` with specific operations. ```bash mvn clean install ./manage_alerts_sample.sh " " ``` -------------------------------- ### Deploy Helloworld with Gradle Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/flexible/java-8/helloworld/README.md Use this command to deploy the Helloworld sample to App Engine Flexible using Gradle. If Gradle is not installed, use ./gradlew appengineDeploy. ```bash $ gradle appengineDeploy ``` ```bash ./gradlew appengineDeploy ``` -------------------------------- ### Run Downscoping Example (Server-Side) Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/auth/README.md Execute the DownscopingExample for server-side downscoping. You must provide a bucket name and object name in the main method. ```bash mvn exec:java -Dexec.mainClass=com.google.cloud.auth.samples.DownscopingExample ``` -------------------------------- ### Install Compute Engine Prerequisites on Linux Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/compute/cmdline/README.md Installs Git, Maven, and Java JDK on Debian or Ubuntu-based Compute Engine VMs. Ensure Java 8 JDK is installed. ```bash sudo apt-get update sudo apt-get install git maven openjdk-7-jdk -y ``` -------------------------------- ### Write Time Series with Quickstart Sample Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/monitoring/cloud-client/README.md Run the QuickstartSample using Maven to write a time series to a metric. Ensure you replace YOUR_PROJECT_ID with your actual Google Cloud project ID. ```bash mvn exec:java -Dexec.mainClass=com.example.monitoring.QuickstartSample \ -DprojectId=YOUR_PROJECT_ID ``` -------------------------------- ### Assemble Spark Samples with sbt Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/bigtable/spark/README.md Use this sbt command to build a fat jar containing all sample applications and their dependencies. This is required before running any Spark examples. ```bash sbt clean assembly ``` -------------------------------- ### Set Environment Variables for BigQueryKmsKey Example Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/dataflow/encryption-keys/README.md Configure necessary environment variables for the BigQueryKmsKey example, including project ID, GCS bucket, and Cloud KMS key details. ```sh # Set the project ID, GCS bucket and KMS key. export PROJECT=$(gcloud config get-value project) export BUCKET=your-gcs-bucket # Set the KMS key ID. export KMS_KEYRING=samples-keyring export KMS_KEY=samples-key export KMS_KEY_ID=$(gcloud kms keys list --location global --keyring $KMS_KEYRING --filter $KMS_KEY --format "value(NAME)") # Output BigQuery dataset and table name. export DATASET=samples export TABLE=dataflow_kms ``` -------------------------------- ### Install App Engine Simple Jetty Main Locally Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/appengine-java11/helloworld-servlet/README.md Navigate to the appengine-simple-jetty-main directory and install it locally using Maven. This makes the dependency available for the main application. ```bash cd ../appengine-simple-jetty-main mvn install ``` -------------------------------- ### List Buckets on Compute Engine Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/auth/README.md Run an example that lists buckets while authenticated as a Google Compute Engine instance. This uses the instance's service account credentials. ```bash mvn exec:java -Dexec.mainClass=com.google.cloud.auth.samples.AuthExample -Dexec.args="compute" ``` -------------------------------- ### Copy Example Secrets File Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/auth/src/main/java/com/google/cloud/auth/samples/customcredentials/aws/README.md Copy the example secrets file to a new file for local development configuration. This file should not be committed to version control. ```bash cp custom-credentials-aws-secrets.json.example custom-credentials-aws-secrets.json ``` -------------------------------- ### Run environment setup script Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/retail/interactive-tutorials/README.md Execute this script to quickly set up your working environment for the Retail API. It automates the process of creating a service account and configuring necessary permissions. ```bash bash java-docs-samples/retail/interactive-tutorials/user_environment_setup.sh ``` -------------------------------- ### Build Java Samples with Maven Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/video/README.md Use this Maven command to clean and package the Java samples, skipping tests for a faster build. Ensure Maven is installed. ```bash mvn clean package -DskipTests=True ``` -------------------------------- ### Run gRPC Server and Client Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/endpoints/getting-started-grpc/README.md Starts the gRPC server and then runs the client to test the service. The server must be running before the client is executed. ```bash java -jar server/build/libs/server.jar ``` ```bash java -jar client/build/libs/client.jar --help ``` ```bash java -jar client/build/libs/client.jar --greetee 'Endpoints!' ``` -------------------------------- ### List Buckets with JSON Credentials Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/auth/README.md Run an example that lists buckets using credentials from a JSON file. Specify the path to your credentials JSON file using -Dexec.args. ```bash mvn exec:java -Dexec.mainClass=com.google.cloud.auth.samples.AuthExample -Dexec.args="explicit [path-to-credentials-json]" ``` -------------------------------- ### Run Cloud Spanner JDBC Example with Maven Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/spanner/jdbc/README.md Execute the sample application using Maven. Replace `` with the desired operation and provide your instance and database names. ```bash mvn clean compile exec:java -Dexec.args=" my-instance my-database" ``` -------------------------------- ### Run Spanner Leaderboard Sample Commands Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/spanner/leaderboard/README.md Execute the Spanner Leaderboard sample with `java -jar leaderboard.jar` to view available commands and examples. ```bash @shell:~/.../target$ java -jar leaderboard.jar Leaderboard 1.0.0 Usage: java -jar leaderboard.jar [command_option] Examples: java -jar leaderboard.jar create my-instance example-db - Create a sample Cloud Spanner database along with sample tables in your project. java -jar leaderboard.jar insert my-instance example-db players - Insert 100 sample Player records into the database. java -jar leaderboard.jar insert my-instance example-db scores - Insert sample score data into Scores sample Cloud Spanner database table. java -jar leaderboard.jar query my-instance example-db - Query players with top ten scores of all time. java -jar leaderboard.jar query my-instance example-db 168 - Query players with top ten scores within a timespan specified in hours. java -jar leaderboard.jar delete my-instance example-db - Delete sample Cloud Spanner database. ``` -------------------------------- ### Run Java Bookstore Server Locally Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/endpoints/bookstore-grpc/README.md Start the Java Bookstore gRPC server locally. It listens on port 8000 by default. ```bash java -jar ./server/build/libs/server.jar ``` -------------------------------- ### App Engine Java 11 Entrypoint Configuration Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/appengine-java11/appengine-simple-jetty-main/README.md Sets the runtime to `java11` and specifies the entrypoint to start the Jetty server and load the WAR file. ```yaml runtime: java11 entrypoint: 'java -cp "*" com.example.appengine.jetty.Main helloworld.war' ``` -------------------------------- ### Run App Engine Sample Locally with Maven Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/appengine-java21/ee8/analytics/README.md Use this Maven command to run the App Engine sample application locally. Ensure you have Maven installed and configured. ```bash $ mvn appengine:run ``` -------------------------------- ### Verify Maven installation Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/dataflow/README.md Confirm that Apache Maven is installed correctly by checking its version. Follow the Maven installation guide for your OS if it's not found. ```sh mvn --version ``` -------------------------------- ### Install Required Packages on Compute Engine Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/compute/signed-metadata/README.md Installs git-core, OpenJDK 8, and Maven on a Compute Engine instance. Ensure Java 8 is selected if multiple versions are installed. ```bash sudo apt-get update && sudo apt-get install git-core openjdk-8-jdk maven ``` ```bash sudo update-alternatives --config java ``` -------------------------------- ### Build Sample Project with Gradle Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/appengine-java8/endpoints-v2-guice/README.md Execute this command to build the sample project on Unix-based systems using Gradle. Windows users should use gradlew.bat. ```bash ./gradlew build ``` -------------------------------- ### Run Kafka Server Locally with Docker Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/dataflow/flex-templates/kafka_to_bigquery/README.md Use these commands to create a Docker network, build the Kafka image, and run a Kafka container locally. Ensure Docker is installed. ```sh # Create a network where containers can communicate. docker network create kafka-net # Build the image. docker image build -t kafka kafka/ # Run a detached container (in the background) using the network we created. docker run -d --rm \ --name "kafka" \ --net "kafka-net" \ -p 2181:2181 -p 9092:9092 \ kafka ``` ```sh # Stop the container. docker kill kafka # Delete the Docker network. docker network rm kafka-net ``` -------------------------------- ### Verify Java installation Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/dataflow/README.md Check if the Java Development Kit (JDK) is installed and accessible by running this command. Ensure JAVA_HOME is set correctly. ```sh $JAVA_HOME/bin/java --version ``` -------------------------------- ### Deploy App Engine App with Gradle Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/appengine-java8/helloworld/README.md Execute this Gradle command to deploy your application to Google App Engine. If Gradle is not installed, use the provided wrapper script. Access the deployed application at https://YOUR-PROJECT-ID.appspot.com. ```bash gradle appengineDeploy ``` ```bash ./gradlew appengineDeploy ``` -------------------------------- ### Clone the sample app Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/appengine-java8/pubsub/README.md Clone the repository and navigate to the sample directory. ```bash git clone https://github.com/GoogleCloudPlatform/java-docs-samples cd java-docs-samples/appengine-java8/pubsub ``` -------------------------------- ### Create Vert.x Web Client, Router, and HTTP Server Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/appengine-java11/vertx-helloworld/README.md This Java code sets up a Vert.x Web client to query the Google metadata API, configures a router to handle requests, and starts an HTTP server on port 8080. The handler `handleDefault` is used for all routes. ```java webClient = WebClient.create(vertx); Router router = Router.router(vertx); router.route().handler(this::handleDefault); vertx.createHttpServer() .requestHandler(router) .listen(8080, ar -> startFuture.handle(ar.mapEmpty())); ``` -------------------------------- ### Start Bigtable Proxy Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/bigtable/bigtable-proxy/README.md Start the Bigtable proxy on a specified port. The proxy can forward requests for multiple Bigtable projects, instances, and tables, while exporting health metrics to a single designated project. ```sh # Then start the proxy on the specified port. The proxy can forward requests for multiple # Bigtable projects/instances/tables. However it will export health metrics to a single project # specified by `metrics-project-id`. ./bigtable-proxy.sh \ --listen-port=1234 \ --metrics-project-id=SOME_GCP_PROJECT ``` -------------------------------- ### Install App Engine Simple Jetty Main Dependency Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/appengine-java11/oauth2/README.md Install the App Engine Simple Jetty Main dependency to your local Maven repository. This makes the main class available on your classpath for the sample app. ```bash cd java-docs-samples/appengine-java11/appengine-simple-jetty-main mvn install ``` -------------------------------- ### Run CopyTable Spark Example Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/bigtable/spark/README.md Submit the CopyTable Spark application using spark-submit. This example copies data from one Bigtable table to another. It requires the HBase Spark connector package and specifies the main class and assembly jar. ```bash $SPARK_HOME/bin/spark-submit \ --packages org.apache.hbase.connectors.spark:hbase-spark:1.0.0 \ --class example.CopyTable \ $BIGTABLE_SPARK_ASSEMBLY_JAR \ $BIGTABLE_SPARK_PROJECT_ID $BIGTABLE_SPARK_INSTANCE_ID \ $BIGTABLE_SPARK_WORDCOUNT_TABLE $BIGTABLE_SPARK_COPYTABLE_TABLE ``` -------------------------------- ### Create Pub/Sub Topic Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/eventarc/pubsub/README.md Use this command to create a Cloud Pub/Sub topic. Ensure you have the gcloud CLI installed and configured. ```sh gcloud pubsub topics create my-topic ``` -------------------------------- ### Clone the sample app Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/appengine-java8/translate-pubsub/README.md Clone the sample application repository and navigate to the specific sample directory. ```bash git clone https://github.com/GoogleCloudPlatform/java-docs-samples cd java-docs-samples/appengine-java8/translate-pubsub ``` -------------------------------- ### Delete Compute Engine Instance Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/compute/cmdline/README.md Example command to delete a specific Compute Engine VM instance in a given zone. ```bash gcloud compute instances delete my-sample-instance --zone us-central1-f ``` -------------------------------- ### Set environment variables and run the app Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/flexible/java-8/pubsub/README.md Configure the necessary environment variables for Pub/Sub topic and verification token, then run the application using Maven. Access the application at http://localhost:8080/. ```bash export PUBSUB_TOPIC= export PUBSUB_VERIFICATION_TOKEN= mvn jetty:run ``` -------------------------------- ### Create Bigtable Table Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/bigtable/beam/helloworld/README.md Use this command to create a Bigtable table with a specified column family. Ensure you have the cbt tool installed and configured. ```bash cbt createtable mobile-time-series families="stats_summary" ``` -------------------------------- ### Navigate to Retail Interactive Tutorials Directory Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/retail/interactive-tutorials/README.md Navigate to the specific directory for the Retail API interactive tutorials in Java. ```bash cd java-docs-samples/retail/interactive-tutorials ``` -------------------------------- ### Deploy Datastore Sample with Maven Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/appengine-java21/ee8/datastore/README.md Deploy the Datastore sample application and its indexes using Maven. Replace placeholders with your project ID and a version number. ```bash $ mvn clean package appengine:deploy $ mvn appengine:deployIndex ``` -------------------------------- ### Clone the sample app Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/flexible/java-11/pubsub/README.md Clone the repository and navigate to the sample directory. ```sh git clone https://github.com/GoogleCloudPlatform/java-docs-samples cd java-docs-samples/flexible/pubsub ``` -------------------------------- ### Run Dataflow Job from Template Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/bigtable/beam/workload-generator/README.md Use this command to start a Dataflow job from the workload generator template. Ensure environment variables are set. ```bash JOB_NAME="generate-bigtable-workload" gcloud dataflow flex-template run $JOB_NAME \ --template-file-gcs-location "$TEMPLATE_PATH" \ --parameters bigtableInstanceId="$INSTANCE_ID" \ --parameters bigtableTableId="$TABLE_ID" \ --region "$REGION" \ --parameters workloadRate=$WORKLOAD_RATE --parameters workloadDurationMinutes=$WORKLOAD_DURATION ``` -------------------------------- ### Build the App Engine Java Guestbook Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/appengine-java8/taskqueues-deferred/README.md Use this command to package the application. It also runs tests. ```bash mvn package ``` -------------------------------- ### Hibernate Insert Statements Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/spanner/hibernate/README.md Example of SQL insert statements generated by Hibernate when saving Person and associated Payment entities to Cloud Spanner. ```sql Hibernate: insert into PersonsTable (address, name, nickname, id) values (?, ?, ?, ?) Hibernate: insert into Payment (amount, id) values (?, ?) Hibernate: insert into WireTransferPayment (wire_id, id) values (?, ?) Hibernate: insert into Payment (amount, id) values (?, ?) Hibernate: insert into CreditCardPayment (credit_card_id, id) values (?, ?) ... ``` -------------------------------- ### Initialize Google Cloud SDK Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/appengine-java11/spanner/README.md Run these commands to initialize the Google Cloud SDK and create an App Engine application if it's your first time. ```bash gcloud init ``` ```bash gcloud app create ``` -------------------------------- ### Deploy App Engine Sample with Maven Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/appengine-java21/ee8/analytics/README.md Use this Maven command to package and deploy your App Engine sample application. This command cleans the project, packages it, and then deploys it. ```bash $ mvn clean package appengine:deploy ``` -------------------------------- ### Navigate to Sample Directory Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/pubsub/streaming-analytics/README.md Navigate to the streaming analytics samples directory within the cloned repository. ```bash cd java-docs-samples/pubsub/streaming-analytics ``` -------------------------------- ### Create GCS Bucket and Upload Products Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/retail/interactive-tutorials/README.md Compile and run a Java class using Maven to create a Cloud Storage bucket and upload product data. ```bash mvn compile exec:java -Dexec.mainClass=product.setup.ProductsCreateGcsBucket ``` -------------------------------- ### Create a Cloud Tasks queue Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/appengine-java8/tasks/app/README.md Use this gcloud command to create a new Cloud Tasks queue. Ensure you have the Cloud SDK installed and configured. ```bash gcloud tasks queues create default ``` -------------------------------- ### Run App Locally with Maven Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/appengine-java21/ee8/bigquery/README.md Run the App Engine application locally using the Maven wrapper. Access the application at http://localhost:8080/ after it starts. ```bash mvn appengine:run ``` -------------------------------- ### Clone Java Compute Engine Samples Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/compute/cmdline/README.md Downloads the sample code repository and navigates to the command-line sample directory. ```bash mkdir some_directory cd some_directory git clone https://github.com/GoogleCloudPlatform/java-docs-samples.git cd java-docs-samples/compute/cmdline ``` -------------------------------- ### Create a service account and key Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/dataflow/README.md This script creates a service account, assigns it the 'Project Owner' role, and generates a JSON key file for authentication. Ensure you replace 'path/to/your/credentials.json' with the desired location for the key file. ```sh export PROJECT=$(gcloud config get-value project) export SA_NAME=samples export IAM_ACCOUNT=$SA_NAME@$PROJECT.iam.gserviceaccount.com # Create the service account. gcloud iam service-accounts create $SA_NAME --display-name $SA_NAME # Set the role to Project Owner (*). gcloud projects add-iam-policy-binding $PROJECT \ --member serviceAccount:$IAM_ACCOUNT \ --role roles/owner # Create a JSON file with the service account credentials. export GOOGLE_APPLICATION_CREDENTIALS=path/to/your/credentials.json gcloud iam service-accounts keys create $GOOGLE_APPLICATION_CREDENTIALS \ --iam-account=$IAM_ACCOUNT ``` -------------------------------- ### Get GCE Instance External IP Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/endpoints/getting-started-grpc/README.md Retrieves the external IP address of the GCE instance. This IP is needed to connect the client to the deployed service. ```bash gcloud compute instances list ``` -------------------------------- ### Clone and Build Java Docs Sample Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/compute/signed-metadata/README.md Clones the Java docs samples repository and navigates to the signed-metadata directory. Packages the application using Maven. ```bash git clone https://github.com/GoogleCloudPlatform/java-docs-samples.git ``` ```bash cd java-docs-samples/compute/signed-metadata/ ``` ```bash mvn clean package ``` -------------------------------- ### Run Pub/Sub Application with Gradle Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/pubsub/spring/README.md Use this command to build and run the Spring Boot application using Gradle. Ensure you have Java and Gradle installed and configured. ```sh gradle bootRun ``` -------------------------------- ### Initialize Vert.x and Deploy Server Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/appengine-java11/vertx-helloworld/README.md This Java code initializes a Vert.x instance and deploys the Server Verticle. Ensure Vert.x is included as a dependency. ```java Vertx vertx = Vertx.vertx(); vertx.deployVerticle(new Server()); ``` -------------------------------- ### Run Pub/Sub Application with Maven Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/pubsub/spring/README.md Use this command to build and run the Spring Boot application using Maven. Ensure you have Java and Maven installed and configured. ```sh mvn clean spring-boot:run ``` -------------------------------- ### Navigate to Application Directory Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/spanner/leaderboard/README.md Change directory to the version of the application you want to run. ```bash cd complete ``` -------------------------------- ### Execute Packaged Java Sample Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/compute/error-reporting/README.md Run the packaged Java sample JAR file, which includes dependencies, to send logs to Stackdriver. ```bash java -jar compute-stackdriver-1.0-SNAPSHOT-jar-with-dependencies.jar ``` -------------------------------- ### Deploy Cloud Function for Vulnerabilities Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/container-registry/vulnerability-notification-function/README.md Deploy the Java Cloud Function to process Pub/Sub notifications for container vulnerabilities. Ensure you have Maven installed and configured for the build. ```bash mvn package gcloud functions deploy vulnerability-function \ --entry-point com.example.containeranalysis.VulnerabilityFunction \ --runtime java11 \ --trigger-topic container-analysis-occurrences-v1 \ --memory 512MB ``` -------------------------------- ### Create App Engine Project Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/appengine-java11/oauth2/README.md Create a new App Engine project if this is your first time. This command sets up the necessary infrastructure for your application on App Engine. ```bash gcloud app create ``` -------------------------------- ### Run Specific Retail API Code Sample Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/retail/interactive-tutorials/README.md Use Maven to compile and execute a specific Java code sample class for the Retail API. ```bash mvn compile exec:java -Dexec.mainClass="package.CodeSampleClass" ``` -------------------------------- ### Clone Sample App Repository Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/appengine-java11/oauth2/README.md Clone the Java documentation samples repository to your local machine. This provides the necessary code base for the sample application. ```bash git clone https://github.com/GoogleCloudPlatform/java-docs-samples ``` -------------------------------- ### Run Application Locally with Exec Maven Plugin Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/appengine-java11/appengine-simple-jetty-main/README.md Starts the embedded Jetty server locally, using the Exec Maven Plugin with the WAR file as an argument. ```bash mvn exec:java -Dexec.args="../sample/target/sample.war" ``` -------------------------------- ### Navigate to Kafka to BigQuery Sample Directory Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/dataflow/flex-templates/kafka_to_bigquery/README.md Change the current directory to the Kafka to BigQuery sample within the cloned repository. ```bash cd java-docs-samples/dataflow/flex-templates/kafka_to_bigquery ``` -------------------------------- ### Get Cloud SQL Server Certificate Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/cloud-sql/mysql/servlet/README.md Use the gcloud CLI to list and download the server certificate for your Cloud SQL instance to ensure encrypted connections. ```bash gcloud beta sql ssl server-ca-certs list --instance=INSTANCE_NAME ``` ```bash gcloud beta sql ssl server-ca-certs create --instance=INSTANCE_NAME ``` ```bash gcloud beta sql ssl server-ca-certs list \ --format="value(cert)" \ --instance=INSTANCE_NAME > \ server-ca.pem ``` -------------------------------- ### Build Application with Maven Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/spanner/leaderboard/README.md Run the Maven command to build the application. Tests are skipped. ```bash mvn install -DskipTests ``` -------------------------------- ### Create and Import Client Keystore Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/cloud-sql/mysql/servlet/README.md Convert client certificate and key files into a PKCS #12 archive and then import them into a Java keystore. This enables the Java application to authenticate with the Cloud SQL instance. ```bash openssl pkcs12 -export -in client-cert.pem -inkey client-key.pem \ -name "mysqlclient" -passout pass:mypassword -out client-keystore.p12 ``` ```bash keytool -importkeystore -srckeystore client-keystore.p12 -srcstoretype pkcs12 \ -srcstorepass -destkeystore -deststoretype JKS -deststorepass ``` -------------------------------- ### Consume Messages from Kafka Topic Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/dataflow/flex-templates/kafka_to_bigquery/README.md Use the kafka-console-consumer.sh script in a Docker container to consume and display messages from a Kafka topic, starting from the beginning. Press Ctrl+C to exit. ```bash docker run -it --rm --network host apache/kafka:3.9.1 \ /opt/kafka/bin/kafka-console-consumer.sh \ --bootstrap-server localhost:9092 --topic --from-beginning ``` -------------------------------- ### Clone Repository and Navigate Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/dataflow/flex-templates/streaming_beam_sql/README.md Clones the java-docs-samples repository and navigates to the specific code sample directory. ```sh git clone https://github.com/GoogleCloudPlatform/java-docs-samples.git cd java-docs-samples/dataflow/flex-templates/streaming_beam_sql ``` -------------------------------- ### Hibernate HQL Query and Output Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/spanner/hibernate/README.md Example of an HQL query to retrieve a saved Person entity and the resulting output, including the generated UUID and associated payment amount. ```java Hibernate: select person0_.id as id1_0_, person0_.address as address2_0_, person0_.name as name3_0_, person0_.nickname as nickname4_0_ from PersonsTable person0_ There are 1 persons saved in the table: Person{ id=688377a3-b884-4beb-886d-6e93317c5542 name='person' nickname='purson' address='address' payment_amount=800 } ``` -------------------------------- ### Run Sample Container Locally Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/eventarc/README.md Execute the built container locally, mapping the host port to the container's port and setting the PORT environment variable. Replace `PROJECT_ID` and `SAMPLE_NAME` with your specific values. ```bash PORT=8080 && docker run --rm -p 9090:${PORT} -e PORT=${PORT} gcr.io/PROJECT_ID/SAMPLE_NAME ``` -------------------------------- ### Execute Java Compute Engine Sample Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/compute/cmdline/README.md Executes the compiled Java sample code using Maven. This will list VM instances and manage 'my-sample-instance'. ```bash mvn -q exec:java ``` -------------------------------- ### Example Song Rank Output Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/bigtable/beam/change-streams/README.md Sample output from the Song Rank pipeline, showing top songs and their listen counts at different timestamps. This illustrates the format of the results. ```text 2023-07-06T19:53:38.232Z [KV{The Wheels on the Bus, 199}, KV{Twinkle, Twinkle, Little Star, 199}, KV{Ode to Joy , 192}, KV{Row, Row, Row Your Boat, 186}, KV{Take Me Out to the Ball Game, 182}] 2023-07-06T19:53:49.536Z [KV{Old MacDonald Had a Farm, 20}, KV{Take Me Out to the Ball Game, 18}, KV{Für Elise, 17}, KV{Ode to Joy , 15}, KV{Mary Had a Little Lamb, 12}] 2023-07-06T19:53:50.425Z [KV{Twinkle, Twinkle, Little Star, 20}, KV{The Wheels on the Bus, 17}, KV{Row, Row, Row Your Boat, 13}, KV{Happy Birthday to You, 12}, KV{Over the Rainbow, 9}] ``` -------------------------------- ### Run Pub/Sub Lite to Cloud Storage sample with Maven Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/pubsublite/streaming-analytics/README.md Execute the Pub/Sub Lite to Cloud Storage streaming pipeline using Maven. This command requires the Pub/Sub Lite subscription, Cloud Storage output path, and Dataflow runner configuration. ```sh mvn compile exec:java \ -Dexec.mainClass=examples.PubsubliteToGcs \ -Dexec.args="\ --subscription=projects/$PROJECT_ID/locations/$LITE_LOCATION/subscriptions/$SUBSCRIPTION \ --output=gs://$BUCKET/samples/output \ --windowSize=1 \ --runner=DataflowRunner \ --project=$PROJECT_ID \ --region=$DATAFLOW_REGION \ --tempLocation=gs://$BUCKET/temp" ``` -------------------------------- ### Navigate to Retail Code Samples Directory Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/retail/interactive-tutorials/README.md Change the current directory to the root of the Retail API code samples for Java. ```bash cd java-docs-samples/retail/interactive-tutorials/ ``` -------------------------------- ### Get GKE Load Balancer IP Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/endpoints/getting-started-grpc/README.md Retrieves the external IP address of the GKE service's load balancer. This IP is needed for the client to connect to the service. ```bash kubectl get svc grpc-hello ``` -------------------------------- ### Run Pub/Sub Lite to Cloud Storage sample with Gradle Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/pubsublite/streaming-analytics/README.md Execute the Pub/Sub Lite to Cloud Storage streaming pipeline using Gradle. This command requires the Pub/Sub Lite subscription, Cloud Storage output path, and Dataflow runner configuration. ```sh gradle execute -Dexec.args="\ --subscription=projects/$PROJECT_ID/locations/$LITE_LOCATION/subscriptions/$SUBSCRIPTION \ --output=gs://$BUCKET/samples/output \ --windowSize=1 \ --runner=DataflowRunner \ --project=$PROJECT_ID \ --region=$DATAFLOW_REGION \ --tempLocation=gs://$BUCKET/temp" ``` -------------------------------- ### Deploy App Engine Application using Maven Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/appengine-java11-bundled-services/README.md This command deploys your App Engine application using the Maven App Engine plugin. Ensure Maven is installed and configured. ```Shell mvn appengine:deploy ``` -------------------------------- ### Build Sample Container with Jib Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/eventarc/README.md Compile the sample and build a Docker container locally using the Jib Maven plugin. ```bash mvn compile jib:dockerBuild ``` -------------------------------- ### Build and Run Vision API Face Detection Sample Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/vision/face-detection/README.md Compile and execute the Java sample application using Maven. This command builds the project and runs the face detection on a specified image, saving the output to another file. ```bash mvn clean compile assembly:single java -cp target/vision-face-detection-1.0-SNAPSHOT-jar-with-dependencies.jar com.google.cloud.vision.samples.facedetect.FaceDetectApp data/face.jpg output.jpg ``` -------------------------------- ### Run Bigtable Change Streams Hello World Pipeline Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/bigtable/beam/change-streams/README.md Execute the 'ChangeStreamsHelloWorld' Dataflow pipeline using Maven. This command starts the pipeline that processes Bigtable change streams. ```sh mvn compile exec:java -Dexec.mainClass=ChangeStreamsHelloWorld \ "-Dexec.args=--project=$GOOGLE_CLOUD_PROJECT --bigtableProjectId=$BIGTABLE_PROJECT \ --bigtableInstanceId=$BIGTABLE_INSTANCE_ID --bigtableTableId=$TABLE_ID \ --runner=dataflow --region=$REGION --experiments=use_runner_v2" ``` -------------------------------- ### Run Bigtable Change Streams Hello World Test Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/bigtable/beam/change-streams/README.md Execute the unit tests for the 'ChangeStreamsHelloWorld' example using Maven. Ensure the test environment variables are set correctly. ```sh mvn clean test -Dtest=ChangeStreamsHelloWorldTest ``` -------------------------------- ### Compile OAuth2 Sample App Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/appengine-java11/oauth2/README.md Compile the OAuth2 sample application. This step packages the application and prepares it for deployment. ```bash cd ../oauth2 mvn package ``` -------------------------------- ### Configure Spark Environment Variables Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/bigtable/spark/README.md Set these environment variables to configure your Spark application to connect to the Bigtable emulator or a Cloud Bigtable instance. Ensure SPARK_HOME points to your Spark installation. ```bash SPARK_HOME=/PATH/TO/spark-2.4.8-bin-hadoop2.7 BIGTABLE_SPARK_PROJECT_ID=your-project-id BIGTABLE_SPARK_INSTANCE_ID=your-instance-id BIGTABLE_SPARK_WORDCOUNT_TABLE=wordcount BIGTABLE_SPARK_WORDCOUNT_FILE=src/test/resources/Romeo-and-Juliet-prologue.txt BIGTABLE_SPARK_COPYTABLE_TABLE=copytable ``` -------------------------------- ### Clone Sample App Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/appengine-java21/ee8/bigquery/README.md Clone the sample application repository and navigate to the specific directory for the BigQuery and App Engine integration. ```bash git clone https://github.com/GoogleCloudPlatform/java-docs-samples cd appengine-java21/bigquery ``` -------------------------------- ### Import Products to Retail Catalog Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/retail/interactive-tutorials/README.md Compile and run a Java class using Maven to import prepared products into the Retail API catalog. ```bash mvn compile exec:java -Dexec.mainClass=product.ImportProductsGcs ``` -------------------------------- ### List Output Files in GCS Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/pubsub/streaming-analytics/README.md This command lists the files generated by the pipeline in the specified Google Cloud Storage bucket. Files may take a few minutes to appear after the job starts. ```bash gcloud storage ls gs://$BUCKET_NAME/samples/ ``` -------------------------------- ### Set Environment Variables for Cloud Spanner R2DBC Example Source: https://github.com/googlecloudplatform/java-docs-samples/blob/main/spanner/r2dbc/README.md Configure these environment variables to specify your Google Cloud project, Spanner instance, and database. Ensure these are set before running the application. ```bash export project=[PROJECT] export instance=[INSTANCE] export database=[DATABASE] ```