我曾经使用NetBean IDE自动构建和运行。它适用于Spring。但是,现在我想编写自己的Ant构建文件。它构建成功,唯一的是ClassPathXmlApplicationContext似乎无法在运行时找到类路径。我使用Spring 3.0.5和以下库,放在lib文件夹中:
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
文件夹结构:
DevFortress
+ --- LIB
+ --- SRC
+ config +.......
+ ---构建
+----classes +----jar
我想从devFortress.xml获取一个上下文: ApplicationContext context = new ClassPathXmlApplicationContext(“DevFortress.xml”); 最初,DevFortress.xml位于src包中的config包中。但是,我只想让我的程序运行,所以我将它放入lib文件夹,类和jar中,但它没有希望。
这是我的构建文件:
<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>
这有什么问题?
答案 0 :(得分:0)
您是否尝试过将配置文件包含在jar创建过程中
答案 1 :(得分:0)
另外,我在Spring XML文件中的XML模式:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.6.SEC01.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.6.SEC01.xsd"/>