I used to build and run automatically with NetBean IDE. It works fine with Spring. However, now I want to write my own Ant build file. It builds successfully, the only thing is the ClassPathXmlApplicationContext seems like it can’t find the class path at runtime. I am using Spring 3.0.5 with the following libraries, put in lib folder:
org.springframework.beans-3.0.5.RELEASE.jar
org.springframework.beans-sources-3.0.5.RELEASE.jar
org.springframework.context.support-sources-3.0.5.RELEASE.jar
org.springframework.context-3.0.5.RELEASE.jar
org.springframework.context-sources-3.0.5.RELEASE.jar
org.springframework.core-3.0.5.RELEASE.jar
org.springframework.core-sources-3.0.5.RELEASE.jar
The folder structure:
DevFortress
+—lib
+—src
+ config +.......+—build
+----classes +----jar
I want to get a context from my devFortress.xml:
ApplicationContext context = new ClassPathXmlApplicationContext(“DevFortress.xml”);
Originally, the DevFortress.xml is in config package in src package. However, I just want to make my program run, so I put it into lib folder, classes and jar as well, but it’s hopeless.
Here is my build file:
<project name="DevFortress" basedir="." default="main">
<property name="src.dir" value="src"/>
<property name="config.dir" value="${src.dir}/config"/>
<property name="build.dir" value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir" value="${build.dir}/jar"/>
<property name="main-class" value="Controller.Main"/>
<property name="lib.dir" value="lib"/>
<path id="classpath">
<fileset dir="${lib.dir}" includes="**/*.jar"/>
<fileset dir="${config.dir}" includes="**/*.xml"/>
</path>
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<target name="compile">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath"/>
</target>
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar destfile = "${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
</jar>
</target>
<target name="run" depends = "jar">
<java fork="true" classname="${main-class}">
<classpath>
<path refid="classpath"/>
<path location="${jar.dir}/${ant.project.name}.jar"/>
</classpath>
</java>
</target>
<target name="clean-build" depends="clean,jar"/>
<target name="main" depends="clean,run"/>
</project>
What’s wrong with this?
have you tried just including the configuration files into the jar creation process