Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Cette page explique comment générer une bibliothèque cliente à partir de votre API backend. Toute application Java ou Android peut utiliser cette bibliothèque pour appeler l'API.
Les instructions suivantes indiquent comment utiliser les plug-ins Apache Maven et Gradle de Cloud Endpoints Frameworks pour générer un groupe de clients Gradle à partir de l'exemple de projet Maven de la page relative aux premiers pas avec Endpoints Frameworks.
Pour générer une bibliothèque cliente :
Créez votre API.
Exécutez l'outil de ligne de commande Endpoints Frameworks comme suit :
Maven
mvnendpoints-framework:clientLibs
Gradle
gradleendpointsClientLibs
Patientez le temps que l'outil génère la bibliothèque. Si l'opération aboutit, l'outil affiche un message semblable à celui-ci :
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
Décompressez le fichier à l'aide de l'utilitaire unzip ou d'un autre utilitaire de désarchivage compatible ZIP :
unzip./echo-v1-java.zip
Changez de répertoire :
cdecho
Créez la bibliothèque cliente :
Maven
mvncleanpackage
La sortie se trouve dans le répertoire target/.
Le nom exact du fichier dépend de la version du client Java. Il devrait ressembler à echo-v1-1.23.0-SNAPSHOT.jar.
Gradle
gradlebuild
La sortie se trouve dans le répertoire build/libs. Le nom exact du fichier dépend de la version du client Java. Il devrait ressembler à echo-v1-1.23.0-SNAPSHOT.jar.
Ajoutez le fichier JAR de la bibliothèque cliente à votre application Java ou Android.
Répétez ces étapes chaque fois que vous modifiez le code de l'API.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 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)."]]