gpt4 book ai didi

java - 为什么在 ant 中编译时出现许多缺少类的错误?

转载 作者:行者123 更新时间:2023-12-01 05:20:27 25 4
gpt4 key购买 nike

让我在这里添加更多信息。我有一个 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 中生成的

最佳答案

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

所以首先编译java并将其放在正确的文件夹中才能成功执行。

了解如何使用javac task in ANT

关于java - 为什么在 ant 中编译时出现许多缺少类的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10495702/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com