How do I get the base url of my server with JAX-RS? Basically I want ""http://localhost:8080/.." when the program is on localhost and "http://www.theSite.com/..." when the program is on a live server. I am using Jersey Framework.
Asked
Active
Viewed 2.3k times
2 Answers
40
Yes, you may use myUri = uri.getBaseUri();
Here how you get the Uri object :
@Path("myresource")
public class MyResource{
@Context
UriInfo uri;
@GET
public String myresponse(){
URI myUri = uri.getBaseUri();
return ...
}
}
You will have plenty of informations with UriInfo. Check here the javadoc.

Christoph Böhme
- 3,766
- 1
- 19
- 29

Nicolas Zozol
- 6,910
- 3
- 50
- 74