IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Services Web Java Discussion :

Lancement d'un client REST avec l'invite de commande


Sujet :

Services Web Java

  1. #1
    Futur Membre du Club
    Femme Profil pro
    etudiante
    Inscrit en
    Mars 2018
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : etudiante
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2018
    Messages : 12
    Points : 7
    Points
    7
    Par défaut Lancement d'un client REST avec l'invite de commande
    Bonjour à tous,

    Comment lancer un client java REST avec le console?
    merci d'avance

  2. #2
    Expert confirmé Avatar de yildiz-online
    Homme Profil pro
    Architecte de domaine
    Inscrit en
    Octobre 2011
    Messages
    1 444
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Architecte de domaine

    Informations forums :
    Inscription : Octobre 2011
    Messages : 1 444
    Points : 4 563
    Points
    4 563
    Par défaut
    un client rest c'est juste un appel HTTP, un curl fera donc l'affaire sous linux (et sous windows 10 à partir de la prochaine mise à jour)

    https://curl.haxx.se/docs/manpage.html
    PXL le retro-gaming facile: Essayez-le

    Yildiz-Engine an open-source modular game engine: Website
    Yildiz-Online a 3D MMORTS in alpha: Facebook page / Youtube page

  3. #3
    Futur Membre du Club
    Femme Profil pro
    etudiante
    Inscrit en
    Mars 2018
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : etudiante
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2018
    Messages : 12
    Points : 7
    Points
    7
    Par défaut
    j'ai tapé ça: javac ClientJava.java
    il m'affiche ces erreurs:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    ClientJava.java:5: error: package javax.ws.rs does not exist
    import javax.ws.rs.Path;
                      ^
    ClientJava.java:6: error: package javax.ws.rs.client does not exist
    import javax.ws.rs.client.Client;
                             ^
    ClientJava.java:7: error: package javax.ws.rs.client does not exist
    import javax.ws.rs.client.ClientBuilder;
                             ^
    ClientJava.java:8: error: package javax.ws.rs.client does not exist
    import javax.ws.rs.client.WebTarget;
                             ^
    ClientJava.java:9: error: package javax.ws.rs.core does not exist
    import javax.ws.rs.core.MediaType;
                           ^
    ClientJava.java:10: error: package javax.ws.rs.core does not exist
    import javax.ws.rs.core.Response;
                           ^
    ClientJava.java:11: error: package javax.ws.rs.core does not exist
    import javax.ws.rs.core.UriBuilder;
                           ^
    ClientJava.java:13: error: package org.glassfish.jersey.client does not exist
    import org.glassfish.jersey.client.ClientConfig;
                                      ^
    ClientJava.java:16: error: cannot find symbol
            ClientConfig config = new ClientConfig();
            ^
      symbol:   class ClientConfig
      location: class ClientJava
    ClientJava.java:16: error: cannot find symbol
            ClientConfig config = new ClientConfig();
                                      ^
      symbol:   class ClientConfig
      location: class ClientJava
    ClientJava.java:18: error: cannot find symbol
            Client client = ClientBuilder.newClient(config);//Creating an Instance of a Client
            ^
      symbol:   class Client
      location: class ClientJava
    ClientJava.java:18: error: cannot find symbol
            Client client = ClientBuilder.newClient(config);//Creating an Instance of a Client
                            ^
      symbol:   variable ClientBuilder
      location: class ClientJava
    ClientJava.java:20: error: cannot find symbol
            WebTarget target = client.target(getBaseURI());// Creating a WebTarget using the URI of the targeted web resource:
            ^
      symbol:   class WebTarget
      location: class ClientJava
    ClientJava.java:22: error: cannot find symbol
            String response = target.path("aleatoire").path("oper1").request().accept(MediaType.TEXT_PLAIN).get(String.class);
                                                                                      ^
      symbol:   variable MediaType
      location: class ClientJava
    ClientJava.java:25: error: cannot find symbol
            String response2 = target.path("aleatoire").path("oper2").request().accept(MediaType.TEXT_PLAIN).get(String.class);
                                                                                       ^
      symbol:   variable MediaType
      location: class ClientJava
    ClientJava.java:31: error: cannot find symbol
                    return UriBuilder.fromUri("http://localhost:8081/WSalea").build();// nouvelle instance Ó partir d'une uri
                           ^
      symbol:   variable UriBuilder
      location: class ClientJava
    16 errors
    donc comment importer les bibliothèques jersey(sous windows)

  4. #4
    Expert confirmé Avatar de yildiz-online
    Homme Profil pro
    Architecte de domaine
    Inscrit en
    Octobre 2011
    Messages
    1 444
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Architecte de domaine

    Informations forums :
    Inscription : Octobre 2011
    Messages : 1 444
    Points : 4 563
    Points
    4 563
    Par défaut
    ok ce n'est pas lancer mais compiler

    -cp pour ajouter un jar au classpath
    PXL le retro-gaming facile: Essayez-le

    Yildiz-Engine an open-source modular game engine: Website
    Yildiz-Online a 3D MMORTS in alpha: Facebook page / Youtube page

  5. #5
    Futur Membre du Club
    Femme Profil pro
    etudiante
    Inscrit en
    Mars 2018
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : etudiante
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2018
    Messages : 12
    Points : 7
    Points
    7
    Par défaut
    j'ai importer tous les fichiers jar avec:
    javac -classpath javax.servlet-api-3.0.1.jar;javax.ws.rs-api-2.1.jar;jaxb-api-2.2.7.jar;jboss-interceptors-api_1.1_spec-1.0.0.Beta1.jar;jersey-client.jar;jersey-common.jar;jersey-container-servlet.jar;jersey-container-servlet-core.jar;jersey-hk2.jar;jersey-media-jaxb.jar;jersey-media-json-binding.jar;jersey-media-sse.jar;jersey-server.jar;jsr250-api-1.0.jar;org.osgi.core-4.2.0.jar;osgi-resource-locator-1.0.1.jar;persistence-api-1.0.jar;validation-api-1.1.0.Final.jar;yasson-1.0.jar;aopalliance-repackaged-2.5.0-b42.jar;cdi-api-1.1.jar;el-api-2.2.jar;hk2-api-2.5.0-b42.jar;hk2-locator-2.5.0-b42.jar;hk2-utils-2.5.0-b42.jar;javassist-3.22.0-CR2.jar;javax.annotation-api-1.2.jar;javax.inject-1.jar;javax.inject-2.5.0-b42.jar;javax.json.bind-api-1.0.jar;javax.json-1.1.jar;javax.json-api-1.1.jar ..\..\..\src\clientUC\ClientJava.java

    mais il affiche:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    warning: javax.ws.rs-api-2.1.jar(javax/ws/rs/Path.class): major version 52 is newer than 51, the highest major version supported by this compiler.
      It is recommended that the compiler be upgraded.
    warning: javax.ws.rs-api-2.1.jar(javax/ws/rs/client/Client.class): major version 52 is newer than 51, the highest major version supported by this compiler.
      It is recommended that the compiler be upgraded.
    warning: javax.ws.rs-api-2.1.jar(javax/ws/rs/client/ClientBuilder.class): major version 52 is newer than 51, the highest major version supported by this compiler.
      It is recommended that the compiler be upgraded.
    warning: javax.ws.rs-api-2.1.jar(javax/ws/rs/client/WebTarget.class): major version 52 is newer than 51, the highest major version supported by this compiler.
      It is recommended that the compiler be upg.

  6. #6
    Expert confirmé Avatar de yildiz-online
    Homme Profil pro
    Architecte de domaine
    Inscrit en
    Octobre 2011
    Messages
    1 444
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Architecte de domaine

    Informations forums :
    Inscription : Octobre 2011
    Messages : 1 444
    Points : 4 563
    Points
    4 563
    Par défaut
    les librairies sont apparemment compilées en java 8 et toi tu utilises java 7
    PXL le retro-gaming facile: Essayez-le

    Yildiz-Engine an open-source modular game engine: Website
    Yildiz-Online a 3D MMORTS in alpha: Facebook page / Youtube page

  7. #7
    Futur Membre du Club
    Femme Profil pro
    etudiante
    Inscrit en
    Mars 2018
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : etudiante
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2018
    Messages : 12
    Points : 7
    Points
    7
    Par défaut Error: A JNI error has occurred, please check your installation and try again
    j'ai changé la version java et tous va bien avec
    j
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    avac -classpath javax.servlet-api-3.0.1.jar;javax.ws.rs-api-2.1.jar;jaxb-api-2.2.7.jar;jboss-interceptors-api_1.1_spec-1.0.0.Beta1.jar;jersey-client.jar;jersey-common.jar;jersey-container-servlet.jar;jersey-container-servlet-core.jar;jersey-hk2.jar;jersey-media-jaxb.jar;jersey-media-json-binding.jar;jersey-media-sse.jar;jersey-server.jar;jsr250-api-1.0.jar;org.osgi.core-4.2.0.jar;osgi-resource-locator-1.0.1.jar;persistence-api-1.0.jar;validation-api-1.1.0.Final.jar;yasson-1.0.jar;aopalliance-repackaged-2.5.0-b42.jar;cdi-api-1.1.jar;el-api-2.2.jar;hk2-api-2.5.0-b42.jar;hk2-locator-2.5.0-b42.jar;hk2-utils-2.5.0-b42.jar;javassist-3.22.0-CR2.jar;javax.annotation-api-1.2.jar;javax.inject-1.jar;javax.inject-2.5.0-b42.jar;javax.json.bind-api-1.0.jar;javax.json-1.1.jar;javax.json-api-1.1.jar ..\..\..\src\ClientJava.java
    mais aprés j'ai tapé: >java ClientJava
    il m'affiche:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    Error: A JNI error has occurred, please check your installation and try again
    Exception in thread "main" java.lang.NoClassDefFoundError: javax/ws/rs/core/Configuration
            at java.lang.Class.getDeclaredMethods0(Native Method)
            at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
            at java.lang.Class.privateGetMethodRecursive(Unknown Source)
            at java.lang.Class.getMethod0(Unknown Source)
            at java.lang.Class.getMethod(Unknown Source)
            at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
            at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
    Caused by: java.lang.ClassNotFoundException: javax.ws.rs.core.Configuration
            at java.net.URLClassLoader.findClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            ... 7 more

  8. #8
    Expert confirmé Avatar de yildiz-online
    Homme Profil pro
    Architecte de domaine
    Inscrit en
    Octobre 2011
    Messages
    1 444
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Architecte de domaine

    Informations forums :
    Inscription : Octobre 2011
    Messages : 1 444
    Points : 4 563
    Points
    4 563
    Par défaut
    tu as pris java 8 ou 9?
    PXL le retro-gaming facile: Essayez-le

    Yildiz-Engine an open-source modular game engine: Website
    Yildiz-Online a 3D MMORTS in alpha: Facebook page / Youtube page

  9. #9
    Futur Membre du Club
    Femme Profil pro
    etudiante
    Inscrit en
    Mars 2018
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : etudiante
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2018
    Messages : 12
    Points : 7
    Points
    7
    Par défaut
    java 8

  10. #10
    Expert confirmé Avatar de yildiz-online
    Homme Profil pro
    Architecte de domaine
    Inscrit en
    Octobre 2011
    Messages
    1 444
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Architecte de domaine

    Informations forums :
    Inscription : Octobre 2011
    Messages : 1 444
    Points : 4 563
    Points
    4 563
    Par défaut
    Pour lancer ton application tu dois aussi spécifier le classpath, quand tu as compilé, il n'a pas ajouté les libraries dans ton jar, javac les as simplement utilisées pour valider la compilation.

    Il faut donc à nouveau les appeler lors du lancement de l'application.
    PXL le retro-gaming facile: Essayez-le

    Yildiz-Engine an open-source modular game engine: Website
    Yildiz-Online a 3D MMORTS in alpha: Facebook page / Youtube page

  11. #11
    Futur Membre du Club
    Femme Profil pro
    etudiante
    Inscrit en
    Mars 2018
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : etudiante
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2018
    Messages : 12
    Points : 7
    Points
    7
    Par défaut
    il m'affiche
    Erreur : impossible de trouver ou charger la classe principale
    et je suis sure que la classe existe dans le chemin
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    >java -classpath javax.servlet-api-3.0.1.jar;javax.ws.rs-api-2.1.jar;jaxb-api-2.2.7.jar;jboss-interceptors-api_1.1_spec-1.0.0.Beta1.jar;jersey-client.jar;jersey-common.jar;jersey-container-servlet.jar;jersey-container-servlet-core.jar;jersey-hk2.jar;jersey-media-jaxb.jar;jersey-media-json-binding.jar;jersey-media-sse.jar;jersey-server.jar;jsr250-api-1.0.jar;org.osgi.core-4.2.0.jar;osgi-resource-locator-1.0.1.jar;persistence-api-1.0.jar;validation-api-1.1.0.Final.jar;yasson-1.0.jar;aopalliance-repackaged-2.5.0-b42.jar;cdi-api-1.1.jar;el-api-2.2.jar;hk2-api-2.5.0-b42.jar;hk2-locator-2.5.0-b42.jar;hk2-utils-2.5.0-b42.jar;javassist-3.22.0-CR2.jar;javax.annotation-api-1.2.jar;javax.inject-1.jar;javax.inject-2.5.0-b42.jar;javax.json.bind-api-1.0.jar;javax.json-1.1.jar;javax.json-api-1.1.jar ..\..\..\src\ClientJava
    Erreur : impossible de trouver ou charger la classe principale ..\..\..\src\ClientJava

  12. #12
    Expert confirmé Avatar de yildiz-online
    Homme Profil pro
    Architecte de domaine
    Inscrit en
    Octobre 2011
    Messages
    1 444
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Architecte de domaine

    Informations forums :
    Inscription : Octobre 2011
    Messages : 1 444
    Points : 4 563
    Points
    4 563
    Par défaut
    Il y a bien une fonction main dans ClientJava ?
    PXL le retro-gaming facile: Essayez-le

    Yildiz-Engine an open-source modular game engine: Website
    Yildiz-Online a 3D MMORTS in alpha: Facebook page / Youtube page

  13. #13
    Futur Membre du Club
    Femme Profil pro
    etudiante
    Inscrit en
    Mars 2018
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : etudiante
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2018
    Messages : 12
    Points : 7
    Points
    7
    Par défaut
    oui, c'est le code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    import java.net.URI;
     
    import javax.ws.rs.Path;
    import javax.ws.rs.client.Client;
    import javax.ws.rs.client.ClientBuilder;
    import javax.ws.rs.client.WebTarget;
    import javax.ws.rs.core.MediaType;
    import javax.ws.rs.core.Response;
    import javax.ws.rs.core.UriBuilder;
     
    import org.glassfish.jersey.client.ClientConfig;
    public class ClientJava{
    	public static void main(String[] args) {
            ClientConfig config = new ClientConfig();
     
            Client client = ClientBuilder.newClient(config);//Creating an Instance of a Client
     
            WebTarget target = client.target(getBaseURI());// Creating a WebTarget using the URI of the targeted web resource:
     
            String response = target.path("aleatoire").path("oper1").request().accept(MediaType.TEXT_PLAIN).get(String.class);
     
            System.out.println(response);
            String response2 = target.path("aleatoire").path("oper2").request().accept(MediaType.TEXT_PLAIN).get(String.class);
     
            System.out.println(response2);
     
        }
    	 private static URI getBaseURI() {//chemin de l'application
    	        return UriBuilder.fromUri("http://localhost:8082/WSalea").build();
    }

  14. #14
    Expert confirmé Avatar de yildiz-online
    Homme Profil pro
    Architecte de domaine
    Inscrit en
    Octobre 2011
    Messages
    1 444
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Architecte de domaine

    Informations forums :
    Inscription : Octobre 2011
    Messages : 1 444
    Points : 4 563
    Points
    4 563
    Par défaut
    alors c'est peut-être bien le chemin relatif ../src/Client qui ne passe pas
    PXL le retro-gaming facile: Essayez-le

    Yildiz-Engine an open-source modular game engine: Website
    Yildiz-Online a 3D MMORTS in alpha: Facebook page / Youtube page

Discussions similaires

  1. Client REST avec CXF/Jax-RS, query hardcodée
    Par tchize_ dans le forum Services Web
    Réponses: 0
    Dernier message: 14/03/2017, 16h01
  2. Réponses: 3
    Dernier message: 11/05/2010, 19h51
  3. Réponses: 2
    Dernier message: 07/04/2008, 13h35
  4. [Access 2003] Communiquer avec l'invite de commande
    Par Faboul dans le forum VBA Access
    Réponses: 1
    Dernier message: 01/03/2008, 19h28
  5. se déplacer avec l'invite de commandes (windows xp)
    Par kriskikout dans le forum Langage
    Réponses: 9
    Dernier message: 05/05/2006, 15h59

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo