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

ご覧のとおり、他のクラスを認識できません。何故ですか ?メインで参照されている他のクラスを認識させるためにここでできることはありますか? これらの不足しているクラスは、パッケージ org.jibx.starter で生成されます

4

1 に答える 1

0

ANT の Java タスクは、.class ファイルを必要とする Java コマンドと同じです。

したがって、最初にJavaをコンパイルし、適切なフォルダーに配置して正常に実行します。

ANT で javac タスクを使用する方法を学ぶ

于 2012-05-08T09:32:40.190 に答える