【发布时间】:2019-10-14 13:03:00
【问题描述】:
我在尝试运行 Javadoc ant 任务时收到来自 Ant 的错误消息。
“构建失败 /data/data/com.termux/files/home/LearnJava/Observer/build.xml:39:没有指定源文件、包和模块。”
构建文件位于:
https://github.com/Fernal73/LearnJava/blob/master/Observer/build.properties
version=1.0.0
main.class=com.javacodegeeks.patterns.observerpattern.TestObserver
main.class1=com.javacodegeeks.patterns.observerpattern.Test
cs.properties=../checkstyle.properties
gformat.properties=../gformat.properties
ant.build.javac.source=1.7
ant.build.javac.target=1.7
packages=com.javacodegeeks.patterns.observerpatern.*
和 https://github.com/Fernal73/LearnJava/blob/master/Observer/build.xml
<?xml version="1.0"?>
<project name="Observer" default="main"
basedir=".">
<property file = "build.properties"/>
<property file = "${cs.properties}"/>
<property file = "${gformat.properties}"/>
<!-- Sets variables which can later be used. -->
<!-- The value of a property is accessed via ${} -->
<property name="src.dir" location="." />
<property name="build.dir" location="." />
<property name="dist.dir" location="dist" />
<property name="docs.dir" location="docs" />
<taskdef resource="${cs.taskdef.resource}"
classpath="../${cs.jar}"/>
<!-- Deletes the existing build, docs and dist directory-->
<target name="clean">
<delete>
<fileset dir="." includes="**/*.class"/>
</delete>
<delete dir="${docs.dir}" />
<delete dir="${dist.dir}" />
</target>
<!-- Creates the build, docs and dist directory-->
<target name="makedir">
<mkdir dir="${docs.dir}" />
<mkdir dir="${dist.dir}" />
</target>
<!-- Compiles the java code (including the usage of library for JUnit -->
<target name="compile" depends="clean, makedir,gformat,checkstyle">
<javac includeantruntime="false" srcdir="${src.dir}" destdir="${build.dir}">
<compilerarg value="-Xlint:-options"/>
</javac>
</target>
<!-- Creates Javadoc -->
<target name="docs" depends="compile">
<javadoc packagenames="${packages}" additionalparam="-Xdoclint:none"
sourcepath="${src.dir}"
destdir="${docs.dir}">
<!-- Define which files / directory should get included, we include all -->
<fileset dir="${src.dir}">
<include name="*.java" />
</fileset>
</javadoc>
</target>
<target name="manifest">
<tstamp/>
<manifest file="manifest.mf">
<attribute name="Built-By" value="${user.name}"/>
<section name="common">
<attribute name="Specification-Title" value="${ant.project.name}"/>
<attribute name="Specification-Version" value="${version}"/>
<attribute name="Specification-Vendor" value=""/>
<attribute name="Implementation-Title" value=""/>
<attribute name="Implementation-Version" value="${build} ${TODAY}"/>
<attribute name="Implementation-Vendor" value=""/>
</section>
<attribute name="Main-Class" value="${main.class}" />
</manifest>
</target>
<!--Creates the deployable jar file -->
<target name="jar" depends="compile,manifest">
<jar destfile="${dist.dir}\${ant.project.name}.jar" basedir="${build.dir}" includes="**/*.class"
manifest="manifest.mf">
</jar>
</target>
<target name="run" >
<description>Run target</description>
<java classname="${main.class}">
<classpath>
<pathelement location="${dist.dir}\${ant.project.name}.jar"/>
<pathelement path="${java.class.path}"/>
</classpath>
</java>
</target>
<target name="gformat">
<exec executable="find" dir="${basedir}"
failonerror="true" outputproperty="sources">
<arg line=" . -type f -name '*.java'"/>
</exec>
<echo message="About to format ...: ${sources}"/>
<java classname="${gformat.main.class}">
<arg line=" -i ${sources}"/>
<classpath>
<pathelement location="../${gformat.jar}"/>
<pathelement path="${java.class.path}"/>
</classpath>
</java>
</target>
<target name="checkstyle">
<first id="checkstylefile">
<fileset dir=".." includes="${cs.config}"/>
</first>
<checkstyle config="${toString:checkstylefile}"
classpath="../${cs.jar}"
failOnViolation="false" properties="${cs.properties}">
<fileset dir="${src.dir}" includes="**/*.java"/>
<formatter type="plain"/>
<formatter type="plain" toFile="${cs.output}"/>
</checkstyle>
</target>
<target name="main" depends="compile, jar, docs">
<description>Main target</description>
</target>
</project>
分别。
我在仓库中的其他项目也有类似的配置。
它们按预期工作。
我是否遗漏了一些明显的东西?
我确实错过了一些明显的东西。属性包中的额外“t”。显然,几个小时后,我将需要两双眼睛,或者新的一套!
现在,我该如何关闭它?
【问题讨论】:
-
将您的构建文件作为代码格式化块包含在您的问题本身中。随着时间的推移,外部链接可能会变得陈旧(例如,如果您的项目被移动或删除),这将使您的问题对未来的读者毫无用处。另外,请附上您看到的错误消息的全文。
-
谢谢。我已经在帖子中包含了文件内容。我之前遇到了问题; Stackoverflow 一直要求四个空格缩进。该错误特定于观察者项目。存储库中的其他项目没有错误。您对陈旧的链接是正确的;从那以后我本可以找到解决办法的!
-
“我是否遗漏了一些明显的东西?”你是;现在是 2019 年,没有人应该使用 Ant。
-
啊!没关系。根据您的说法,也没有人应该使用脚本。我在 Termux 上开始了这个,除了 Dalvikvm 之外,它无法访问 Java 环境。然后我转移到 Termux 上的 Arch Linux,但希望保留现有的目录结构。 Ant 过去和现在都更具可配置性。 Maven 和/或 Gradle 将不得不等待。顺便说一句,这都是通过命令行完成的。没有 Eclipse 或任何其他 IDE。如果您不相信我,请查看我的其他问题。
-
别听阿比吉特的。 Ant 是迄今为止最好的 Java 构建工具。 (哦,Maven 和 Gradle 在后台使用 Ant。)