[英]Spring is error with Ant build file
我曾經使用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
文件夾結構:
開發堡壘
+-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>
這怎么了
您是否嘗試過僅將配置文件包含在jar創建過程中
另外,我在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"/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.