How to get the server URL with context path


i would like to access information about the current server URL and context path for link generation. Can you give me a hint what bean i have to inject to get these information in a service for example? An example i would thing of is:

// in development
myUrlInformationBean.getFullUrl() == "http://localhost:8080/app"

// in production
myUrlInformationBean.getFullUrl() == ""

Bye, Mario

As the application blocks (web and middleware) can be deployed to different locations, there is no reliable way to get the application (i.e. web UI) URL on all tiers.
Therefore we recommend to set up the cuba.webAppUrl application property on all tiers and use it through the GlobalConfig configuration interface:

private GlobalConfig globalConfig;
private void myMethod() {
	String myUrl = globalConfig.getWebAppUrl();

You can define a development value for the property right in the source files of your project ( in core, in web), and deployment value in files in tomcat/conf/app-core, tomcat/conf/app.

1 Like

hi konstantin,

works like a charme - thx!