Install Spring through maven

这一生的挚爱 提交于 2019-12-13 04:14:34

问题


I am new in using maven, I am having a java class as follow:

 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());
   }
 }

I am having an ant built file as follow:

 <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>

When I run the ant built file I get the error:

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

Is there anything else I have to include in my ant file to make it run?

来源:https://stackoverflow.com/questions/19073898/install-spring-through-maven

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!