gpt4 book ai didi

构建 : Unable to write output 时发生 Java 错误

转载 作者:行者123 更新时间:2023-11-30 06:59:25 26 4
gpt4 key购买 nike

我正在尝试构建我的项目,但它不起作用。我的源 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 时,会发生以下错误:

Error: Could not find or load main class .

我不确定这些错误是否相关。

最佳答案

缺少以下行:

<mkdir dir="test-report"/>

现在完美运行!

关于构建 : Unable to write output 时发生 Java 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41187584/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com