2016-12-16 100 views
0

我試圖建立我的項目,但它不工作。我的源的build.xml:構建Java錯誤:無法寫輸出

<?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出現以下錯誤:

Error: Could not find or load main class .

我不知道,如果錯誤是相關的。

回答

0

下面一行丟失:

<mkdir dir="test-report"/> 

現在完美的作品!

相關問題