Under WEB-INF/classes folder i have java class files structured in package hierarchy(e.g: com.company.app) and resources folder that contains spring context xml, jdbc.properties file, log4j.properties file and other resources that I use in mu app. To load spring context and configure log4j in web.xml i use
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
and in applicationContext.xml I use property-placeholder to locate jdbc.properties file
<context:property-placeholder location="classpath:jdbc.properties"/>
However tomcat says that that classpath resource can not be resolved. I use ant to build a war file and have next target to compile java sources and copy evererything except java sources from src folder to WEB-INF/classes
<target name="javac" description="Compile java source to bytecode">
<mkdir dir="${war_web_inf}/classes" />
<javac srcdir="src" includes="**" encoding="utf-8" destdir="WebContent/WEB-INF/classes" source="1.5" target="1.5" nowarn="true" debug="true" debuglevel="lines,vars,source">
<classpath refid="project.class.path" />
</javac>
<copy todir="${war_web_inf}/classes">
<fileset dir="src" excludes="**/*.java" />
</copy>
</target>
How can I have access to resources in web.xml as classpath:log4j.properties for example?
The contents of your resources dir should be copied directly to WEB-INF/classes, so if your structure is:
You should use something like