Sunday, February 24, 2008

Java: Eclipe's notion of classpath 101

In Eclipse, if you don't specify the build path, your classes by default will be placed in the base classpath of your project module. E.g.
C:\workspaces\myproject\myModuleEJB\classes\xxx

Therefore, your base classpath is C:\workspaces\myproject\myModuleEJB\classes\xxx

Consider two spring config source folders :
C:\workspaces\myproject\myModuleEJB\testsrc\spring\testApplicationContext.xml
C:\workspaces\myproject\myModuleEJB\configsrc\spring\businessRules.xml

testApplicationContext.xml is referring to businessRules.xml e.g.

testApplicationContext.xml
===================

<bean id="businessRules" init="false" class="org.springframework.context.support.ClassPathXmlApplicationContext">
<constructor-arg>
<list><value>spring/businessRules.xml</value></list>
</constructor-arg>
</bean>


both testApplicationContext.xml and businessRules.xml are compiled by Eclipse into
C:\workspaces\myproject\myModuleEJB\classes\spring\testApplicationContext.xml
C:\workspaces\myproject\myModuleEJB\classes\spring\businessRules.xml

therefore, if testApplicationContext.xml wants to refer to businessRules.xml, the testApplicationContext.xml has to refer to the base classpath location of businessRules.xml
ie. /spring/businessRules.xml

No comments: