How to get the web application root?

I am writing a plugin that needs to locate the
root of my web application.
(The case is that I am parsing JSP files and need to
know where my include files are located when the include
statement begins with a "/")

Attila

1 comment
Comment actions Permalink

I have found a solution which works.
First I get the project file, something like this:

Project project = (Project)event.getDataContext().getData(DataConstants.PROJECT);
VirtualFile pf = project.getProjectFile();

Inside the project file I look for the component:
"WebRootContainer"

If the path contains $PROJECT_DIR$, here is the code to get it:

ProjectRootManager projectManager = ProjectRootManager.getInstance(project);
VirtualFile rootFiles[] = projectManager.getRootFiles(ProjectRootType.PROJECT);

The path should in most cases be here:
rootFiles[0].getPath());

0

Please sign in to leave a comment.