我正在尝试构建我的项目,但它无法正常工作。我的源码build.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project name="Optin" default="package" basedir=".">
<path id="master-classpath">
<fileset dir="lib">
<include name="**/*"/>
</fileset>
</path>
<path id="test-lib">
<fileset dir="test-lib">
<include name="**/*"/>
</fileset>
</path>
<!-- Cleans previous builds -->
<target name="clean">
<echo message="Cleaning older builds..."/>
<!-- Cleans the work folder -->
<delete includeemptydirs="true">
<fileset dir="work" includes="**/*"/>
<fileset dir="build" includes="**/*"/>
</delete>
</target>
<!-- Compiles the classes -->
<target name="compile" depends="clean">
<echo message="Compiling..."/>
<mkdir dir="build/classes"/>
<javac includeantruntime="false" srcdir="src" destdir="build/classes" compiler="javac1.7" target="1.7">
<classpath refid="master-classpath"/>
</javac>
<mkdir dir="build/tests"/>
<javac includeantruntime="false" srcdir="tests" destdir="build/tests" compiler="javac1.7" target="1.7">
<classpath refid="master-classpath"/>
<classpath refid="test-lib" />
</javac>
</target>
<!-- Run junit tests -->
<target name="tests" depends="compile">
<echo message="Running tests..."/>
<junit printsummary="yes" haltonfailure="true">
<classpath refid="master-classpath"/>
<classpath refid="test-lib" />
<classpath>
<pathelement location="build/classes"/>
<pathelement location="build/tests"/>
</classpath>
<formatter type="xml" />
<formatter type="plain" />
<batchtest todir="test-report">
<fileset dir="tests">
<include name="**/*Test*.java" />
</fileset>
</batchtest>
</junit>
</target>
<!-- Prepares the package to go -->
<target name="package" depends="tests">
<echo message="Packing..."/>
<!-- Gets the timestamp of this build -->
<tstamp>
<format property="timestamp" pattern="yyyyMMdd_HHmmss"/>
</tstamp>
<input message="Please select the target environment:" addproperty="destenv" defaultvalue="dev" validargs="dev,fqa"/>
<!-- Creates the jar -->
<mkdir dir="work/bin"/>
<jar destfile="work/bin/optin.jar" basedir="build/classes">
<manifest>
<attribute name="Main-Class" value="com.vilt.tim.optin.App"/>
</manifest>
</jar>
<!-- Creates the directory structure -->
<mkdir dir="work/conf"/>
<mkdir dir="work/lib"/>
<mkdir dir="work/logs"/>
<mkdir dir="work/input"/>
<mkdir dir="work/output"/>
<!-- Copies the additional resources -->
<copy todir="work">
<fileset dir="resources/pack">
<include name="*.*"/>
</fileset>
</copy>
<!-- Copies the related properties -->
<copy todir="work/conf">
<fileset dir="properties/${destenv}">
<include name="*.*"/>
</fileset>
</copy>
<copy todir="work/lib">
<fileset dir="lib">
<include name="**/*"/>
</fileset>
</copy>
<!-- Creates the package -->
<zip destfile="package/${timestamp}_optin_build.zip" basedir="work" update="false" level="9"/>
<!-- Clean everything at the end -->
<antcall target="clean"></antcall>
</target>
但是当我运行它时,我收到以下错误:
Buildfile: C:\Users\renato.silva\git\optin\build.xml
clean:
[echo] Cleaning older builds...
compile:
[echo] Compiling...
[mkdir] Created dir: C:\Users\renato.silva\git\optin\build\classes
[javac] Compiling 11 source files to C:\Users\renato.silva\git\optin\build\classes
[javac] C:\Users\renato.silva\git\optin\lib\spring-context-4.2.6.RELEASE.jar(org/springframework/context/annotation/PropertySource.class): warning: Cannot find annotation method 'value()' in type 'Repeatable': class file for java.lang.annotation.Repeatable not found
[javac] 1 warning
[mkdir] Created dir: C:\Users\renato.silva\git\optin\build\tests
[javac] Compiling 1 source file to C:\Users\renato.silva\git\optin\build\tests
tests:
[echo] Running tests...
[junit] Running com.vilt.tim.optin.AppTest
BUILD FAILED
C:\Users\renato.silva\git\optin\build.xml:52: Unable to write output
Total time: 1 second
但是当我单独运行测试类时,它工作正常。我正在使用Spring注释:
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader=AnnotationConfigContextLoader.class)
public class AppTest {
@Test
public void test(){
Assert.assertTrue(true);
}
}
我错过了什么?
PS:当我评论目标测试行时,构建工作正常,但是当我运行java -jar
时,会发生以下错误:
错误:无法找到或加载主类。
我不确定错误是否相关。
答案 0 :(得分:1)
缺少以下行:
<mkdir dir="test-report"/>
现在完美无缺!