我有一个项目需要访问自己的JAR文件中的资源.当我为项目创建JAR文件时,我想将一个目录复制到该JAR文件中(我想ZIP相当于将目录"添加"到现有的ZIP文件中).我只希望在创建JAR之后发生复制(如果我清理并删除JAR文件,我显然不希望复制发生).
目前构建文件如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<project name="foobar" basedir=".." default="jar">
<!-- project-specific properties -->
<property name="project.path" value="my/project/dir/foobar" />
<patternset id="project.include">
<include name="${project.path}/**" />
</patternset>
<patternset id="project.jar.include">
<include name="${project.path}/**" />
</patternset>
<import file="common-tasks.xml" />
<property name="jar.file" location="${test.dir}/foobar.jar" />
<property name="manifest.file" location="misc/foobar.manifest" />
</project>
Run Code Online (Sandbox Code Playgroud)
一些构建任务是从另一个文件(common-tasks.xml)调用的,我无法在此处显示.
我在ANT脚本中使用了一个findbugs,我无法弄清楚如何解决我的两个错误.我已阅读文档,但不明白.以下是我的错误以及与之相关的代码:
错误1:测试浮点相等性.(FE_FLOATING_POINT_EQUALITY)
private boolean equals(final Quantity other) {
return this.mAmount == convertedAmount(other);
}
Run Code Online (Sandbox Code Playgroud)
错误2:EQ_COMPARETO_USE_OBJECT_EQUALS
public final int compareTo(final Object other) {
return this.description().compareTo(((Decision) other).description());
}
Run Code Online (Sandbox Code Playgroud)
我已经阅读了ComparesTo问题的文档
强烈建议,但并非严格要求(x.compareTo(y)== 0)==(x.equals(y)).一般来说,任何实现Comparable接口并且违反此条件的类都应该清楚地表明这一事实.推荐的语言是"注意:此类具有与equals不一致的自然顺序."
还有关于浮点平等的文档
此操作比较两个浮点值是否相等.由于浮点计算可能涉及舍入,因此计算的浮点值和双精度值可能不准确.对于必须精确的值,例如货币值,请考虑使用固定精度类型,例如BigDecimal.对于不必精确的值,请考虑比较某些范围内的相等性,例如:if(Math.abs(x-y)<.0000001).请参阅Java语言规范,第4.2.4节.
我不明白.有人可以帮忙吗?
我有一个Ant脚本,它使用'copy'任务执行复制操作.它是为Windows编写的,并且有一个硬编码的C:\ path作为'todir'参数.我看到'exec'任务有一个操作系统参数,有没有类似的方法来分支基于操作系统的副本?
Ant exec任务有一个输出属性,可用于告诉Ant输出的位置.我用它将输出重定向到文件.问题是,如果我不对输出做些什么,那么Ant打印的东西并没有那么大的帮助 - 它并不完整.
有没有设置输出属性System.out?
我想执行所有目标而不是指定每个目标.
例如:
<?xml version="1.0"?>
<project name="Kte" default="all" basedir="/home/Kte">
<target name="target1">
</target>
<target name="target2">
</target>
</project>
Run Code Online (Sandbox Code Playgroud)
目前我用过:
$ ant target1
$ ant target2
Run Code Online (Sandbox Code Playgroud)
我想用:
$ ant
Run Code Online (Sandbox Code Playgroud)
并且这两个目标都是构建的(这只是一个例子.现实我有一个很长的改变Ant构建文件与子蚂蚁文件,所以有一个"全部"功能非常方便.
在Ant中,我有一个名为' some_property' 的属性,让我们说它的值是" hello".
我正在尝试使用此属性的值(" hello ")替换文本文件中的占位符作为大写.
所以,我有这个任务:
<replaceregexp match="SOME_PLACE_HOLDER" replace="${some_property}" byline="true">
Run Code Online (Sandbox Code Playgroud)
我希望它能像我有这个任务一样工作:
<replaceregexp match="SOME_PLACE_HOLDER" replace="HELLO" byline="true">
Run Code Online (Sandbox Code Playgroud)
我希望避免使用外部Ant任务(例如Ant-Contrib),因此解决方案需要是一个纯正的正则表达式 - 它必须是可能的!
大写,小写和大写.
谁知道正确的正则表达式?
我在Ant中配置JUnit,以便在每个构建上运行单元测试.我希望失败测试的输出在运行时打印在Ant控制台输出中.我不需要看到后续测试的任何输出.
这是我的build.xml文件的相关位:
<junit>
<classpath>
<pathelement path="${build}"/>
</classpath>
<formatter type="brief" usefile="false"/>
<batchtest>
<fileset dir="${src}" includes="my/tree/junit/"/>
</batchtest>
</junit>
Run Code Online (Sandbox Code Playgroud)
这几乎产生了我想要的东西,Ant输出中详细说明了失败的测试,除了成功的测试还写了以下输出:
[junit] Testsuite: my.tree.junit.ExampleTest
[junit] Tests run: 7, Failures: 0, Errors: 0, Time elapsed: 0.002 sec
我相信我已经尝试了JUnit任务文档中列出的所有组合,包括:
printsummary 属性showoutput 属性formatter 各种各样的元素 type我的用例是ant从命令行运行的.当我编写更多测试时,我不希望后续测试的输出如此之大,以至于失败测试的输出会滚出屏幕.ant除非有一个需要我注意的失败测试,否则我只想保持安静.如何配置Ant/JUnit来执行此操作?
我使用的是Ant 1.6.4和JUnit 4.6.
任何人都可以告诉我为什么我收到此错误消息
Buildfile: C:\Users\Tara\workspace\Testing\build.xml
doc:
[delete] Deleting directory C:\Users\Tara\workspace\Testing\doc
[mkdir] Created dir: C:\Users\Tara\workspace\Testing\doc
[javadoc] Generating Javadoc
[javadoc] Javadoc execution
BUILD FAILED
C:\Users\Tara\workspace\Testing\build.xml:24: Javadoc failed: java.io.IOException: Cannot run program "javadoc.exe": CreateProcess error=2, The system cannot find the file specified
Total time: 206 milliseconds
Run Code Online (Sandbox Code Playgroud)
当我在Eclipse中运行它时?
<project name="SimpleBuildScript" basedir="." default="doc">
<property file="build.properties"/>
<target name="compile" description="Compiles the Task">
<delete dir="${class.dir}"/>
<mkdir dir="${class.dir}"/>
<javac srcdir="src" destdir="classes"/>
</target>
<target name="clean" description="Delete all generated files">
<delete dir="${class.dir}"/>
<delete dir="${jar.dir}"/>
</target>
<target name="doc" description="generate documentation">
<delete dir="${doc.dir}"/>
<mkdir dir="${doc.dir}"/> …Run Code Online (Sandbox Code Playgroud) 我有一些文件:
dir/foo.txt
dir/bar.txt
dir/foobar.txt
Run Code Online (Sandbox Code Playgroud)
在Ant apply任务中,我想将文件列表作为参数传递:
<target name="atask">
<apply executable="${cmd}" parallel="false" verbose="true">
<arg value="-in"/>
<srcfile/>
<arg value="dir/foo.txt"/>
<arg value="dir/bar.txt"/>
<arg value="dir/foobar.txt"/>
<fileset dir="${list.dir}" includes="*.list"/>
</apply>
</target>
Run Code Online (Sandbox Code Playgroud)
这工作正常,但如果我想使用文件集动态选择文件列表,该怎么办:
<fileset dir="dir" includes="*.txt"/>
Run Code Online (Sandbox Code Playgroud)
如何将此文件集转换为arg元素 - 每个文件一个?就像是:
<arg>
<fileset dir="dir" includes="*.txt"/>
</arg>
Run Code Online (Sandbox Code Playgroud)
代替
<arg value="dir/foo.txt"/>
<arg value="dir/bar.txt"/>
<arg value="dir/foobar.txt"/>
Run Code Online (Sandbox Code Playgroud)
(此示例不起作用,因为arg不支持文件集)
什么之间的区别@{property},并${property}在访问Ant属性?
在Ant手册中没有看到任何关于它的明显说明.