Take the 2-minute tour ×

In short: I don't know which folder to place the "spring-context.xml" file in a WebApp when I'm doing this:


In Long: I know what a classpath is basically. It used to be an environment variable that told the Java project where to look for jars and other resources. It doesn't seem to be used much. But in Eclipse, it talks about setting your classpath by going into your Java Build Path.

What I don't understand it when I want to find a Spring "spring-context.xml" file using the classpath (above) what that has to do with the Eclipse Java Build Path, if anything! What folders does a WebApp look in when I use the above statement? I usually hear people say, "In the classpath" but that doesn't tell me much since I don't want to use an environment variable and the Eclipse Java Build Path seems to have little to do with finding the spring-context.xml file.

More Detail

Initially I was afraid that more details would confuse the situation, but maybe they hold a key.

I am using Vaadin to create a web app. I'm following their direction for how to get a Spring context into Vaadin. I've created a Spring Helper class:

public SpringContextHelper(Application application) {
    ServletContext servletContext = ((WebApplicationContext) application.getContext()).getHttpSession().getServletContext();
    context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);

In the web.xml I have these sections:



I'm getting the error in the first line of SpringContextHelper(). I've broken the line down so I know it is this logic that is failing:

WebApplicationContext wac = (WebApplicationContext) application.getContext();

wac comes back null, presumably because is can't find the spring-context.xml file.

share|improve this question
"It doesn't seem to be used much": this is a huge misconception. "But in Eclipse, it talks about setting your classpath by going into your Java Build Path.": not necessarily, some paths are by default already covered by the classpath, such as src folder, WebContent/WEB-INF/lib, WebContent/WEB-INF/classes, etc. So whatever you drop there, it will "automagically" end up in webapp's runtime classpath (that's among others what an IDE is good for; so that you don't need to fiddle with javac -cp everytime and so on). –  BalusC Apr 17 '12 at 20:51
So "src", "WebContent/WEB-INF/lib", and "WebContent/WEB-INF/classes". How do I know what "WebContent" is? I thought it was "webapp". And what other paths are built in? –  ksnortum Apr 17 '12 at 21:39
I am talking in Eclipse's perspective. "WebContent" is the default name of public web content folder of a dynamic web project. Other paths are among others Server/lib, JRE/lib and JRE/lib/ext, etc. You can find them all out during runtime by ClassLoader#getResources(). –  BalusC Apr 17 '12 at 21:42
ClassLoader#getResources() seems to need a name and my problem is I don't know where to put spring-context.xml. If I use that as the name, I get nothing back. On another note, where would I find the name of the public web content folder of a dynamic web project? –  ksnortum Apr 17 '12 at 22:27
As an use example, use classLoader.getResources(""). As to the XML file not being found, just put it in one of the default paths covered by the webapp's runtime classpath, or add its path to the webapp's runtime classpath. –  BalusC Apr 17 '12 at 23:34

1 Answer 1

Essentially, the "Java Build path" you specify for a project is the CLASSPATH.

And files you put in the "src" root of your "Java Resources" project folder will automatically go in your web app's "classes" subdirectory (i.e will automatically be available as in the runtime CLASSPATH).

For example, if you have a custom log4j.properties file, then it can and should go in your Eclipse project's "src/" root.

As far as "where does spring-context.xml go?", I don't know. This link suggests it should go under META-INF/jsca (at least for WebLogic):


share|improve this answer
My problem is that I can't put my spring-context.xml file in a folder that the statement above in the question will find. I get an error at runtime. Putting spring-context.xml in src still gets a runtime error. –  ksnortum Apr 17 '12 at 22:37
Q: What is the "runtime error"???????????? –  paulsm4 Apr 18 '12 at 2:21
Suggestion: Do a "File, Export as .war" from your Eclipse project. Look at the .war file (there are several ways to do this, including renaming from .war to .zip and looking at the contents with Windows Explorer). That will help show you how your Eclipse project files and directories map to Tomcat/App server runtime files and directories. IMHO... –  paulsm4 Apr 18 '12 at 2:23
@paulsm5: The exception is javax.servlet.ServletException: java.lang.NullPointerException. This happens on this line: HttpSession hs = wac.getHttpSession();. wac comes from this: WebApplicationContext wac = (WebApplicationContext) application.getContext();. So my assumption is that it can't find the spring-context.xml file. –  ksnortum Apr 18 '12 at 15:57
@paulsm5: spring-context.xml is in WEB-INF/classes in the war file. What does that mean as to where I should put spring-context.xml in the Eclipse project? –  ksnortum Apr 18 '12 at 20:29

Your Answer


