Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Questa pagina descrive come generare una libreria client dall'API di backend.
Qualsiasi app Java o Android può utilizzare questa libreria per chiamare l'API.
Le istruzioni riportate di seguito mostrano come utilizzare i plug-in Apache Maven e Gradle per i framework Cloud Endpoints per generare un bundle client Gradle dal progetto Maven di esempio Introduzione a Endpoints.
Per generare una libreria client:
Creare l'API
Esegui lo strumento a riga di comando Endpoints Frameworks in modo simile a quanto segue:
Maven
mvnendpoints-framework:clientLibs
Gradle
gradleendpointsClientLibs
Attendi che lo strumento generi la libreria. Al termine dell'operazione, lo strumento visualizza un messaggio simile al seguente:
Maven
API client library written to target/client-libs/echo-v1-java.zip
Gradle
API client library written to build/endpointsClientLibs/echo-v1-java.zip
Estrai il file utilizzando l'utilità unzip o un'altra utility di estrazione supportata da ZIP:
unzip./echo-v1-java.zip
Cambia directory:
cdecho
Compila la libreria client:
Maven
mvncleanpackage
L'output si trova nella directory target/.
Il nome file esatto dipende dalla versione del client Java. È simile a echo-v1-1.23.0-SNAPSHOT.jar.
Gradle
gradlebuild
L'output si trova nella directory build/libs. Il nome file esatto dipende dalla versione del client Java. È simile a echo-v1-1.23.0-SNAPSHOT.jar.
Aggiungi il file JAR della libreria client alla tua app Java o Android.
Ripeti questi passaggi ogni volta che modifichi il codice API.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-04 UTC."],[[["\u003cp\u003eThis guide details the process of generating a client library from a backend API for use in Java or Android applications.\u003c/p\u003e\n"],["\u003cp\u003eThe client library is generated using the Cloud Endpoints Frameworks' Apache Maven or Gradle plugins, through command-line instructions.\u003c/p\u003e\n"],["\u003cp\u003eAfter building the API, run either \u003ccode\u003emvn endpoints-framework:clientLibs\u003c/code\u003e or \u003ccode\u003egradle endpointsClientLibs\u003c/code\u003e to generate a zip containing the client library.\u003c/p\u003e\n"],["\u003cp\u003eThe generated library ZIP file needs to be unzipped, and then built using either \u003ccode\u003emvn clean package\u003c/code\u003e or \u003ccode\u003egradle build\u003c/code\u003e, producing a JAR file.\u003c/p\u003e\n"],["\u003cp\u003eThe resulting JAR file, found in the target or build/libs directory, should be added to your Java or Android application for it to communicate with the API, and the process must be repeated every time the API is modified.\u003c/p\u003e\n"]]],[],null,["# Generating a client library\n\nThis page describes how to generate a client library from your backend API.\nAny Java or Android app can use this library to call the API.\n\nTo create iOS clients for your API, we recommend that you use\n[Google APIs Objective-C Client Library for REST APIs](https://github.com/google/google-api-objectivec-client-for-rest/wiki).\n\nBefore you begin\n----------------\n\n- [Set up your development environment](/endpoints/docs/frameworks/java/set-up-environment).\n- Make sure you have properly [annotated](/endpoints/docs/frameworks/java/annotate-code) your API.\n\nGenerating the client library\n-----------------------------\n\nThe following instructions demonstrate how to use the Cloud Endpoints Frameworks\n[Apache Maven](/endpoints/docs/frameworks/java/maven-endpoints-frameworks-plugin)\nand [Gradle](/endpoints/docs/frameworks/java/gradle-endpoints-frameworks-plugin)\nplugins to generate a Gradle client bundle from the sample Maven project\n[Getting started with Endpoints](/endpoints/docs/frameworks/java/quickstart-frameworks-java).\n\nTo generate a client library:\n\n1. Build your API\n\n2. Run the Endpoints Frameworks command-line tool similarly to the\n following:\n\n ### Maven\n\n ```bash\n mvn endpoints-framework:clientLibs\n ```\n\n ### Gradle\n\n ```bash\n gradle endpointsClientLibs\n ```\n\n Wait for the tool to generate the library; on success the tool displays a\n message similar to this one: \n\n ### Maven\n\n ```\n API client library written to target/client-libs/echo-v1-java.zip\n ```\n\n ### Gradle\n\n ```\n API client library written to build/endpointsClientLibs/echo-v1-java.zip\n ```\n3. Unzip the file by using the unzip utility, or use another ZIP-compatible\n unarchiving utility:\n\n unzip ./echo-v1-java.zip\n\n4. Change directory:\n\n cd echo\n\n5. Build the client library:\n\n ### Maven\n\n ```bash\n mvn clean package\n ```\n\n The output is in the `target/` directory.\n The exact filename depends on the version of the Java client. It is\n something similar to `echo-v1-1.23.0-SNAPSHOT.jar`.\n\n ### Gradle\n\n ```bash\n gradle build\n ```\n\n The output is in the `build/libs` directory. The\n exact filename depends on the version of the Java client. It is\n something similar to `echo-v1-1.23.0-SNAPSHOT.jar`.\n6. Add the client library JAR to your Java or Android app.\n\n7. Repeat these steps every time you modify your API code.\n\nWhat's next\n-----------\n\n- [Call the backend API from an Android app](/endpoints/docs/frameworks/java/calling-from-android).\n- [Learn more about Cloud Endpoints Frameworks for App Engine](/endpoints/docs/frameworks/java)."]]