Ivy 종속성 관리 라이브러리 (로컬 캐시에 jar가 있음)가있는 Eclipse Spring 프로젝트가 있습니다. @RunWith (SpringJUnit4ClassRunner.class) 주석을 사용하여 일부 JUnit 테스트 클래스를 작성 했으므로 아무 문제없이 Eclipse에서 실행할 수있다. 불행히도 Ant 작업으로 실행할 수는 없습니다. 다음 예외가 있습니다 :Ant JUnit 작업이 Spring 테스트를 실행하지 못함 - Spring 클래스 러너를 찾을 수 없음
Type org.springframework.test.context.junit4.SpringJUnit4ClassRunner not present
java.lang.TypeNotPresentException: Type org.springframework.test.context.junit4.SpringJUnit4ClassRunner not present
at com.sun.proxy.$Proxy4.value(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:424)
at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138)
Caused by: java.lang.ClassNotFoundException: org.springframework.test.context.junit4.SpringJUnit4ClassRunner
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:270)
at java.lang.Class.initAnnotationsIfNecessary(Class.java:3178)
at java.lang.Class.getAnnotation(Class.java:3137)
Ant가 아이비의 캐시를 클래스 패스에 넣지 않은 것처럼 보입니다. Ivy의 캐시 디렉토리를 classpath에 넣으려고했지만 결과가 없습니다. 내가해야 할 일?
내 아이비 의존성 :
<dependencies>
<dependency org="org.springframework" name="spring-core" rev="3.2.8.RELEASE"/>
<dependency org="org.springframework" name="spring-jdbc" rev="3.2.8.RELEASE"/>
<dependency org="org.springframework" name="spring-tx" rev="3.2.8.RELEASE"/>
<dependency org="org.springframework" name="spring-test" rev="3.2.8.RELEASE"/>
<dependency org="mysql" name="mysql-connector-java" rev="5.1.29"/>
<dependency org="junit" name="junit" rev="4.11"/>
</dependencies>
그리고 내 Ant 빌드 파일 :
<?xml version="1.0"?>
<project name="FooBar" basedir="."
xmlns:ivy="antlib:org.apache.ivy.ant">
<property name="dir.jar" value="build/jar"/>
<property name="dir.classes" value="build/classes"/>
<property name="dir.classes.tests" value="build/tests/classes"/>
<ivy:cachepath pathid="ivy.classpath" />
<path id="classpath">
<pathelement location="${dir.classes}" />
</path>
<!-- =================================
target: clean
================================= -->
<target name="clean">
<delete dir="${dir.jar}"/>
<delete dir="${dir.classes}"/>
<delete dir="${dir.classes.tests}"/>
</target>
<!-- =================================
target: resolve
================================= -->
<target name="resolve">
<ivy:cleancache/>
<ivy:resolve/>
<ivy:cachepath pathid="ivy.classpath" />
</target>
<!-- - - - - - - - - - - - - - - - - -
target: build
- - - - - - - - - - - - - - - - - -->
<target name="build">
<mkdir dir="${dir.classes}"/>
<javac srcdir="src" destdir="${dir.classes}"
includeantruntime="false"
classpathref="ivy.classpath" />
</target>
<!-- - - - - - - - - - - - - - - - - -
target: build-tests
- - - - - - - - - - - - - - - - - -->
<target name="build-tests">
<mkdir dir="${dir.classes.tests}"/>
<javac srcdir="test" destdir="${dir.classes.tests}"
includeantruntime="false">
<classpath refid="ivy.classpath"/>
<classpath refid="classpath"/>
</javac>
</target>
<!-- =================================
target: build-all
================================= -->
<target name="build-all" depends="clean, build, build-tests" description="Builds all" />
<!-- =================================
target: clean-test-all
================================= -->
<target name="clean-test-all" depends="clean, build-all" description="Runs all JUnit tests">
<junit printsummary="yes" haltonfailure="yes">
<classpath>
<dirset dir="${user.home}/.ivy2/cache">
<include name="**" />
</dirset>
<pathelement location="ivy.classpath"/>
<pathelement location="${dir.classes}"/>
<pathelement location="${dir.classes.tests}"/>
</classpath>
<batchtest fork="yes">
<fileset dir="junit">
<include name="**/*Test.java"/>
</fileset>
</batchtest>
</junit>
</target>
</project>