Web.xml and classpaths

In just about every example on the net, when you want access a config file in the web.xml it is in the WEB-INF folder, like this:


<context-param>
  <param-name>exampleConfigLocation</param-name>
  <param-value>/WEB-INF/example-config.xml</param-value>
</context-param>

What I want to do is reference my classpath for config files, like this:


<context-param>
  <param-name>exampleConfigLocation</param-name>
  <param-value>/com/example/app/example-config.xml</param-value>
</context-param>

This makes more sense to me, especially in a maven-style project structure where resource files are located in src/main/resources. Is this possible in Java EE? Thanks.

it is up to whatever is reading and interpreting the the param-value to decide whther it should be looking in the classpath or filepath.

That makes sense. Never really thought of it that way. Thanks for the info. :slight_smile:

I’d still stick with conventions. There is nothing wrong with using the WEB-INF and nearly every IDE will assume this. You also don’t have to put it in the classpath as containers class loader will do that for you. Ofc as long as your xml config file is accessible via the classpath it is all up to you. But the guy behind you will understand it better if you stick with convention.

you can put either with classpath: xml file, or file in web.xml, but the file path should be relate to same as web context structure