1

让我在这里添加更多信息。我有一个 ant 构建文件。其中的代码是

<?xml version="1.0"?>


<project basedir="." default="full">

  <property name="jibx-home" value="C:/Jibx"/>


 <!-- make sure required jars are present -->
  <condition property="runtime-jars-found">
    <available file="${jibx-home}/lib/jibx-run.jar"/>
  </condition>
  <condition property="binding-jars-found">
    <and>
      <available file="${jibx-home}/lib/bcel.jar"/>
      <available file="${jibx-home}/lib/jibx-bind.jar"/>
      <available file="${jibx-home}/lib/jibx-run.jar"/>
    </and>
  </condition>
  <available property="extras-jar-found" file="${jibx-home}/lib/jibx-extras.jar"/>

  <!-- set classpath for compiling and running application with JiBX -->
  <path id="classpath">
    <fileset dir="${jibx-home}/lib" includes="*.jar"/>
    <pathelement location="bin"/>
  </path>

  <!-- make sure runtime jars are present -->
  <target name="check-runtime">
    <fail unless="jibx-home">JiBX home directory not found - define JIBX_HOME system property or set path directly in build.xml file.</fail>
    <fail unless="runtime-jars-found">Required JiBX runtime jar jibx-run.jar was not found in JiBX home lib directory (${jibx-home}/lib)</fail>
  </target>

  <!-- make sure extras jars are present -->
  <target name="check-extras" depends="check-runtime">
    <fail unless="extras-jar-found">Required JiBX extras jar jibx-extras.jar was not found in JiBX home lib directory (${jibx-home}/lib)</fail>
  </target>

  <!-- make sure binding jars are present -->
  <target name="check-binding" depends="check-runtime">
    <fail unless="binding-jars-found">Required JiBX binding jar jibx-bind.jar or bcel.jar was not found in JiBX home lib directory (${jibx-home}/lib)</fail>
  </target>

  <!-- clean compiled class files and output file -->
  <target name="clean">
    <delete quiet="true" dir="bin"/>
    <delete quiet="true" dir="gen"/>
  </target>

  <!-- generate as a separate step -->
  <target name="codegen" depends="check-runtime">

    <echo message="Running code generation from schema"/>
    <delete quiet="true" dir="gen"/>
    <mkdir dir="gen"/>
    <java classname="org.jibx.schema.codegen.CodeGen" fork="yes"
        classpathref="classpath" failonerror="true">
      <arg value="-t"/>
      <arg value="gen/src"/>
      <arg value="-w"/>
      <arg value="starter.xsd"/>
    </java>

  </target>

  <!-- generate using customizations as a separate step -->
  <target name="custgen" depends="check-runtime">

    <echo message="Running code generation from schema"/>
    <delete quiet="true" dir="gen"/>
    <mkdir dir="gen"/>
    <java classname="org.jibx.schema.codegen.CodeGen" fork="yes"
        classpathref="classpath" failonerror="true">
      <arg value="-c"/>
      <arg value="custom.xml"/>
      <arg value="-t"/>
      <arg value="gen/src"/>
      <arg value="-w"/>
      <arg value="starter.xsd"/>
    </java>

  </target>

  <!-- compile the classes -->
  <target name="compile" depends="check-runtime">

    <echo message="Compiling Java source code"/>
    <mkdir dir="bin"/>
    <javac srcdir="gen/src" destdir="bin" debug="on">
      <classpath refid="classpath"/>
    </javac>
    <javac srcdir="src" destdir="bin" debug="on">
      <classpath refid="classpath"/>
    </javac>

  </target>

  <!-- bind as a separate step -->
  <target name="bind" depends="check-binding">

    <echo message="Running JiBX binding compiler"/>
    <taskdef name="bind" classname="org.jibx.binding.ant.CompileTask">
      <classpath>
        <fileset dir="${jibx-home}/lib" includes="*.jar"/>
      </classpath>
    </taskdef>
    <bind binding="gen/src/binding.xml">
      <classpath refid="classpath"/>
    </bind>
  </target>

  <!-- run the included test program to read and then write to separate file -->
  <target name="run" depends="check-runtime">
    <echo message="Running the sample application..."/>
    <java classname="org.jibx.starter.Test"  fork="true" failonerror="true">
      <classpath refid="classpath" />
      <arg value="starter.xml"/>
      <arg value="out.xml"/>
    </java>
    <echo message="Generated output document out.xml"/>
  </target>

  <target name="full" depends="codegen,compile,bind,run"/>
  <target name="custom" depends="custgen,compile,bind,run"/>

  <!-- show list of targets -->
  <target name="help">
    <echo message="Targets are:"/>
    <echo/>
    <echo message="clean         delete all class files and generated code"/>
    <echo message="compile       compile class files"/>
    <echo message="codegen       generate code using defaults"/>
    <echo message="bind          compile JiBX bindings"/>
    <echo message="run           run test program"/>
    <echo message="full          full build and run using defaults"/>
    <echo message="custgen       generate code using customizations"/>
    <echo message="custom        full build and run using customizations"/>
  </target>

</project>

我得到的输出是:

Buildfile: D:\Users\Rajesh\workspace\Jib\src\build.xml
check-runtime:
codegen:
     [echo] Running code generation from schema
    [mkdir] Created dir: D:\Users\Rajesh\workspace\Jib\src\gen
     [java] Loaded and validated 1 specified schema(s)
     [java] Generated 5 top-level classes in package org.jibx.starter
     [java] Total classes in model: 5
compile:
     [echo] Compiling Java source code
    [mkdir] Created dir: D:\Users\Rajesh\workspace\Jib\src\bin
    [javac] D:\Users\Rajesh\workspace\Jib\src\build.xml:114: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
    [javac] Compiling 5 source files to D:\Users\Rajesh\workspace\Jib\src\bin
    [javac] D:\Users\Rajesh\workspace\Jib\src\build.xml:117: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
    [javac] Compiling 1 source file to D:\Users\Rajesh\workspace\Jib\src\bin
    [javac] D:\Users\Rajesh\workspace\Jib\src\src\Test.java:33: error: cannot find symbol
    [javac]             IBindingFactory bfact = BindingDirectory.getFactory(Order.class);
    [javac]                                                                 ^
    [javac]   symbol:   class Order
    [javac]   location: class Test
    [javac] D:\Users\Rajesh\workspace\Jib\src\src\Test.java:36: error: cannot find symbol
    [javac]             Order order = (Order)uctx.unmarshalDocument(in, null);
    [javac]             ^
    [javac]   symbol:   class Order
    [javac]   location: class Test
    [javac] D:\Users\Rajesh\workspace\Jib\src\src\Test.java:36: error: cannot find symbol
    [javac]             Order order = (Order)uctx.unmarshalDocument(in, null);
    [javac]                            ^
    [javac]   symbol:   class Order
    [javac]   location: class Test
    [javac] D:\Users\Rajesh\workspace\Jib\src\src\Test.java:40: error: cannot find symbol
    [javac]             for (Iterator<Item> iter = order.getItemList().iterator(); iter.hasNext();) {
    [javac]                           ^
    [javac]   symbol:   class Item
    [javac]   location: class Test
    [javac] D:\Users\Rajesh\workspace\Jib\src\src\Test.java:41: error: cannot find symbol
    [javac]                 Item item = iter.next();
    [javac]                 ^
    [javac]   symbol:   class Item
    [javac]   location: class Test
    [javac] 5 errors

BUILD FAILED
D:\Users\Rajesh\workspace\Jib\src\build.xml:117: Compile failed; see the compiler error output for details.

Total time: 3 seconds

如您所见,它无法识别其他类。这是为什么 ?我可以在这里做些什么来让它识别 main 中引用的其他类吗?这些缺失的类是在包 org.jibx.starter 中生成的

4

1 回答 1

0

ANT 中的 Java 任务与需要 .class 文件的 Java 命令相同。

因此,首先您编译 java 并将其放置在适当的文件夹中以成功执行。

学习如何在 ANT 中使用 javac 任务

于 2012-05-08T09:32:40.190 回答