ERLEDIGT
JA
JA
ANTWORTEN
2
2
ZUGRIFFE
1023
1023
EMPFEHLEN
-
Hallo,
versuche mich seit gestern mit Jersey:
https://jersey.dev.java.net/
Hab das Helloworld Beispiel immer noch nicht zum Laufen bekommen!
Hab viel hin und her probiert, http4e meldet jedes mal das die angefragte Ressource nicht gefunden wird.
https://jersey.dev.java.net/use/getting-started.html
http://www.qalem.de/_jersey/
Code java:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
package com.sun.jersey.samples.helloworld.resources; import javax.ws.rs.GET; import javax.ws.rs.ProduceMime; import javax.ws.rs.Path; // The Java class will be hosted at the URI path "/helloworld" @Path("/helloworld") public class HelloWorldResource { // The Java method will process HTTP GET requests @GET // The Java method will produce content identified by the MIME Media // type "text/plain" @ProduceMime("text/plain") public String getClichedMessage() { // Return some cliched textual content return "Hello World"; } }
-
Hat nun doch geklappt.
Mit folgender URL:
http://localhost:8080/WebTest/helloworld
anstatt:
http://localhost:8080/helloworld
So einfach, aber auch doch so schwierig.
-
25.06.08 11:47 #3
- Registriert seit
- Jun 2002
- Ort
- Saarbrücken (Saarland)
- Beiträge
- 9.886
- Blog-Einträge
- 29
Hallo,
funktioniert wunderbar:
Code java: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
package de.tutorials; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.ProduceMime; import javax.ws.rs.core.Context; import javax.ws.rs.core.UriInfo; // The Java class will be hosted at the URI path "/helloworld" @Path("helloworld") public class HelloWorldResource { @Context private UriInfo context; /** Creates a new instance of HelloWorldResource */ public HelloWorldResource() { } /** * Retrieves representation of an instance of hello.world.HelloWorldResource * @return an instance of java.lang.String */ @GET @ProduceMime("text/plain") public String getClichedMessage() { //Return some cliched textual content return ("Hello World! Here is " + context.getAbsolutePath()); } }
Code java: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
/** * */ package de.tutorials; import com.sun.jersey.api.container.httpserver.HttpServerFactory; import com.sun.net.httpserver.HttpServer; /** * @author Thomas.Darimont * */ public class JerseyExample { /** * @param args */ public static void main(String[] args) throws Exception { HttpServer server = HttpServerFactory.create("http://localhost:9998/"); server.start(); System.out.println("Server running"); System.out.println("Visit: http://localhost:9998/helloworld"); System.out.println("Hit return to stop..."); System.in.read(); System.out.println("Stopping server"); server.stop(0); System.out.println("Server stopped"); } }
Ausgabe: Server console:
Code :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
25.06.2008 11:44:10 com.sun.jersey.api.core.ClasspathResourceConfig init INFO: Scanning for root resource and provider classes in the paths: D:\eclipse\workspaces\workspace-3.4M7\de.tutorials.java\bin D:\stuff\jersey\0.9\jersey-0.9-ea\lib\activation.jar D:\stuff\jersey\0.9\jersey-0.9-ea\lib\ant.jar D:\stuff\jersey\0.9\jersey-0.9-ea\lib\asm-3.1.jar D:\stuff\jersey\0.9\jersey-0.9-ea\lib\comresrcgen.jar D:\stuff\jersey\0.9\jersey-0.9-ea\lib\grizzly-servlet-webserver-1.7.3.2.jar D:\stuff\jersey\0.9\jersey-0.9-ea\lib\http.jar D:\stuff\jersey\0.9\jersey-0.9-ea\lib\jaxb-api.jar D:\stuff\jersey\0.9\jersey-0.9-ea\lib\jaxb-impl.jar D:\stuff\jersey\0.9\jersey-0.9-ea\lib\jaxb-xjc.jar D:\stuff\jersey\0.9\jersey-0.9-ea\lib\jdom-1.0.jar D:\stuff\jersey\0.9\jersey-0.9-ea\lib\jersey.jar D:\stuff\jersey\0.9\jersey-0.9-ea\lib\jettison-1.0-RC1.jar D:\stuff\jersey\0.9\jersey-0.9-ea\lib\jsp-api-2.0-20040521.jar D:\stuff\jersey\0.9\jersey-0.9-ea\lib\jsr173_api.jar D:\stuff\jersey\0.9\jersey-0.9-ea\lib\jsr250-api.jar D:\stuff\jersey\0.9\jersey-0.9-ea\lib\jsr311-api.jar D:\stuff\jersey\0.9\jersey-0.9-ea\lib\localizer.jar D:\stuff\jersey\0.9\jersey-0.9-ea\lib\mail.jar D:\stuff\jersey\0.9\jersey-0.9-ea\lib\persistence-api-1.0.jar D:\stuff\jersey\0.9\jersey-0.9-ea\lib\rome-0.9.jar D:\stuff\jersey\0.9\jersey-0.9-ea\lib\servlet.jar D:\stuff\jersey\0.9\jersey-0.9-ea\lib\wadl2java.jar 25.06.2008 11:44:11 com.sun.jersey.api.core.ClasspathResourceConfig init INFO: Root resource classes found: class de.tutorials.HelloWorldResource 25.06.2008 11:44:11 com.sun.jersey.api.core.ClasspathResourceConfig init INFO: Provider classes found: Server running Visit: http://localhost:9998/helloworld Hit return to stop...
Ausgabe Browser:
Code :1
Hello World! Here is http://localhost:9998/helloworld
Gruß TomJava rocks!
How to become a good Java Programmer?
Does IT in Java and .Net
The only valid measurement of code quality: WTFs / minute
Blog
Xing
Twitter
Ähnliche Themen
-
Restful Webservices with Jersey and Java - Tutorial
Von vogella im Forum Java Technology NewsAntworten: 0Letzter Beitrag: 18.02.10, 04:33 -
jersey
Von Micvkey166 im Forum Enterprise Java (JEE, J2EE, Spring & Co.)Antworten: 0Letzter Beitrag: 08.06.09, 09:45





Zitieren

Login





