Bonjour à tous,
Comment lancer un client java REST avec le console?
merci d'avance![]()
Bonjour à tous,
Comment lancer un client java REST avec le console?
merci d'avance![]()
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
j'ai tapé ça: javac ClientJava.java
il m'affiche ces erreurs:
donc comment importer les bibliothèques jersey(sous windows)
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
ok ce n'est pas lancer mais compiler
-cp pour ajouter un jar au classpath
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.
les librairies sont apparemment compilées en java 8 et toi tu utilises java 7
Partager