我是Apache ant的新创建者。在我的项目中,我使用了MySQL,junit和hibernate库。我正在研究Bitbucket管道,因此有人建议使用ant。因此,我正在创建build.xml文件,并且在此过程中是干净,构建,运行junit测试用例。我做了很多研究如何学习这些东西的研究,但是我被困在某个地方。我在清理目录和构建方面也很成功,但是我坚持检查junit失败测试用例。我试图在Eclipse中运行这些测试用例,它表明测试用例失败,但是如果我通过ant运行,它总是说构建成功。我将提供我的项目结构。
+HiberTest
--HTest
--lib
--mysql
--junit
-- Hibernate..... so many library
--src
-com
-test
**so many junit files**
-com
-utils
**so many files**
--classpath
--.settings
--.project
**and many more files**
--build.xml
这是我的build.xml文件
<project basedir="." default="junit" name="Hibernate test">
<property name="debuglevel" value="source,lines,vars" />
<property name="src.dir" location="HTest/src" />
<property name="build.dir" location="HTest/bin" />
<property name="target" value="1.8" />
<property name="source" value="1.8" />
<property name="test.dir" value="HTest/bin/com/test" />
<path id="classpath">
<pathelement location="bin" />
<pathelement location="HTest/lib/junit3.8.1.jar" />
<pathelement location="HTest/lib/antlr-2.7.7.jar" />
<pathelement location="HTest/lib/byte-buddy-1.10.7.jar" />
<pathelement location="HTest/lib/classmate-1.5.1.jar" />
<pathelement location="HTest/lib/dom4j-2.1.1.jar" />
<pathelement location="HTest/lib/FastInfoset-1.2.15.jar" />
<pathelement location="HTest/lib/hibernate-commons-annotations-5.1.0.Final.jar" />
<pathelement location="HTest/lib/hibernate-core-5.4.11.Final.jar" />
<pathelement location="HTest/lib/istack-commons-runtime-3.0.7.jar" />
<pathelement location="HTest/lib/jandex-2.1.1.Final.jar" />
<pathelement location="HTest/lib/javassist-3.24.0-GA.jar" />
<pathelement location="HTest/lib/javax.activation-api-1.2.0.jar" />
<pathelement location="HTest/lib/javax.persistence-api-2.2.jar" />
<pathelement location="HTest/lib/jaxb-api-2.3.1.jar" />
<pathelement location="HTest/lib/jaxb-runtime-2.3.1.jar" />
<pathelement location="HTest/lib/jboss-logging-3.3.2.Final.jar" />
<pathelement location="HTest/lib/jboss-transaction-api_1.2_spec-1.1.1.Final.jar" />
<pathelement location="HTest/lib/mysql-connector-java-5.1.48.jar" />
<pathelement location="HTest/lib/stax-ex-1.8.jar" />
<pathelement location="HTest/lib/txw2-2.3.1.jar" />
</path>
<target name="clean">
<delete dir="${build.dir}" />
</target>
<target name="init" depends="clean">
<mkdir dir="${build.dir}" />
<copy includeemptydirs="false" todir="${build.dir}">
<fileset dir="${src.dir}">
<exclude name="**/*.launch" />
<exclude name="**/*.java" />
</fileset>
</copy>
</target>
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}" />
<javac debug="true" debuglevel="${debuglevel}" destdir="${build.dir}" includeantruntime="false" source="${source}" target="${target}">
<src path="${src.dir}" />
<classpath refid="classpath" />
</javac>
</target>
<target name="junit" depends="build-project">
<junit printsummary="yes" haltonfailure="yes">
<classpath refid="classpath" />
<classpath location="${test.dir}" />
</junit>
</target>
</project>
It always gives me this output:-
clean:
[delete] Deleting directory F:\Repository\Agile\HiberTest\HTest\bin
init:
[mkdir] Created dir: F:\Repository\Agile\HiberTest\HTest\bin
[copy] Copying 1 file to F:\Repository\Agile\HiberTest\HTest\bin
build-project:
[echo] Hibernate test: F:\Repository\Agile\HiberTest\build.xml
[javac] Compiling 3 source files to F:\Repository\Agile\HiberTest\HTest\bin
junit:
BUILD SUCCESSFUL
Total time: 1 second
我想检查是否junit test失败,然后停止构建过程,如果所有都通过而没有错误,然后我想创建可执行的jar文件
提前感谢
[build从“ build”开始,并且层次结构从不调用junit。尝试更改:
<target depends="build-project" name="junit" />
您将需要添加目标/任务来创建jar文件(可能是<jar>
任务。
更一般而言,如果您运行不带命令行参数的Ant:
<jar>
它将运行为项目指定的默认目标,在您的代码中为$ ant
:
build
仔细检查您的依赖项,我看到您有两条链:
<project basedir="." default="build" name="Hibernate test">
这意味着junit目标通过依赖关系与构建目标无关。
假设您希望构建仍为默认目标,并且希望将junit作为该构建的一部分运行,则可以将构建目标更改为依赖于junit:
build --> build-project --> clean --> init
junit --> build-project
然后您的(单个)依赖链为:
<target name="build" depends="junit" />
我想您可能需要添加一个可能称为“包”的目标才能运行jar任务
build --> junit --> build-project --> clean --> init
提供依赖关系链:
<target name="package" depends="junit">
... jar task etc ...
</target>
<target name="build" depends="package"/>
然后使用默认目标运行的蚂蚁应该执行您想要的操作。