0

我是使用 maven 的新手,我有一个 java 类,如下所示:

 import org.springframework.context.ApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;

 public class DecoupledDataReaderClient {
   private IReader reader = null;
   private ApplicationContext ctx = null;

   public DecoupledDataReaderClient() {
     ctx = new ClassPathXmlApplicationContext("basics-reader-beans.xml");
   }

   private String fetchData() {
     reader = (IReader) ctx.getBean("reader");
     return reader.read();
   }

   public static void main(String[] args) {
     DecoupledDataReaderClient client = new DecoupledDataReaderClient();
     System.out.println("Example 1.3: Got data: " + client.fetchData());
   }
 }

我有一个 ant 构建文件如下:

 <target name="init">
    <artifact:dependencies pathId="dependency.classpath">
        <dependency
            groupId="org.springframework"
            artifactId="spring-context"
            version="3.2.1.RELEASE"
        />
    </artifact:dependencies>    
</target>

<target name="compile" depends="init">  
    <mkdir dir="classes"/>
    <javac srcdir="${src}" destdir="${dest}" includeantruntime="false">

    </javac>
</target>

<target name="jar" depends="compile">
    <mkdir dir="${build}"/>
    <jar destfile="${jar}" basedir="${dest}">
        <manifest>
            <attribute name="Main-Class" value="src.DecoupledDataReaderClient"/>
        </manifest>
    </jar>
</target>

<target name="run" depends="jar">
    <java jar="${jar}" fork="true"/>
</target>

当我运行 ant 构建文件时,出现错误:

     error: package org.springframework.context does not exist
     error: package org.springframework.context.support does not exist

我还必须在我的 ant 文件中包含其他内容以使其运行吗?

4

0 回答 0