Get the root directory name in Java web application if context and root names are different


I have a web application where the context name is different from my root name. For example my root Dir name is myapp and the context path is app. Then how to get the root name (myapp) from the Java web application?


If the application is not deployed with a war file you can use this code that will return the whole address where the application is running.

//request variable is the Java HTTP servlet request object received from an action request.getSession().getServletContext().getRealPath("/");

The code I had given is the one I used in one of my Java EE projects well I didn't deploy my project as a war file due to some reasons

and getting the web application location can be used to get your root directory name


  • What is an Artifact?
  • How to modify search result page given by Solr?
  • Azure Resource Template Deployment issues
  • Deploy same Javascript webapp build to different environments
  • Trouble connecting to Google Cloud SQL server from deployed app
  • Microsoft Chart Controls for Microsoft .NET Framework 4.0
  • “mvn clean generate-source” could not resolve dependencies
  • How to programatically 'login' a user based on 'remember me' cookie when using j
  • Elasticsearch script query involving root and nested values
  • Why use database factory in asp.net mvc?
  • How do I configure context broker accept post requests from my remote sensor?
  • How to run “Deployd” on port 80 instead of port 5000 in webserver.
  • Meteor: Do Something On Email Verification Confirmation
  • OpenGL ES texture problem, 4 duplicate columns and horizontal lines (Android)
  • Cannot resolve symbol 'MyApi'
  • How to get address from latitude and longitude android google map v2 [duplicate]
  • How to redirect a user to a different server and include HTTP basic authentication credentials?
  • Cross-Platform Protobuf Serialization
  • Javascript Callbacks with Object constructor
  • Symfony2: How to get request parameter
  • ActionScript 2 vs ActionScript 3 performance
  • How can I estimate amount of memory left with calling System.gc()?
  • Apache 2.4 - remove | delete | uninstall
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • How to format a variable of double type
  • log4net write single file for each call to log.info
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • Acquiring multiple attributes from .xml file in c#
  • Getting error when using KSoap library to consume .NET web services
  • using HTMLImports.whenReady not working in chrome
  • coudnt use logback because of log4j
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • How can I remove ASP.NET Designer.cs files?
  • JaxB to read class hierarchy
  • Django query for large number of relationships
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • How can I use `wmic` in a Windows PE script?
  • java string with new operator and a literal
  • How to push additional view controllers onto NavigationController but keep the TabBar?