I've written a simple REST service class, and I need to deploy and run it under glassfish server, installed on my eclipse.
What steps have I to do in order to put this restlet service online and reach it from my browser?
This is the code:
import javax.ws.rs.*;
import javax.ws.rs.core.*;
@Path("/myApplication")
public class MailRestlet {
@SuppressWarnings("unused")
@Context
private UriInfo context;
/**
* Default constructor.
*/
public MyRestlet() {
// TODO Auto-generated constructor stub
}
开发者_开发百科
@GET
@Produces("text/html")
public String getHtml() {
return "<html><body><h1>Hello World!!</h1>The service is online!!</body></html>";
}
}
You also need to configure the web.XML file, for example, as in http://download.oracle.com/docs/cd/E19776-01/820-4867/ggrby/index.html
There is also a way to avoid web.XML change, by extending the Application class from jaxrs...
As an alternative to configuring the end point using the web.xml file, you can extend the Application class as described here.
From in Eclipse, you can deploy on the server by:
- Right clicking the project and then Run As > Run on Server.
- Select your server from the list of servers you have connected to Eclipse on the screen that follows and click Next.
- Ensure the project is listed under Configured and click Finish.
- You can also set Eclipse to automatically publish to GlassFish when you change the code. Double click the GlassFish Server on the Server view. Expand the Publishing expandable list and select Automatically publish when resources change.
精彩评论