0

我有以下名为 Test.Java 的文件,其代码是

package example25;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.Iterator;
import org.jibx.runtime.BindingDirectory;
import org.jibx.runtime.IBindingFactory;
import org.jibx.runtime.IMarshallingContext;
import org.jibx.runtime.IUnmarshallingContext;
import org.jibx.runtime.JiBXException;

public class Test 
{   
public static void main(String[] args) 
{

    try
    {

        // unmarshal customer information from file
        IBindingFactory bfact = BindingDirectory.getFactory(Order.class);
        IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
        FileInputStream in = new FileInputStream("D:\\Java Libraries\\jibx\\dwcode2\\starter.xml");
        Order order = (Order)uctx.unmarshalDocument(in, null);

        // compute the total amount of the order
        float total = 0.0f;
        for (Iterator<Item> iter = order.getItemList().iterator(); iter.hasNext();)
        {
            Item item = iter.next();
            total += item.getPrice() * item.getQuantity();
        }
        order.setTotal(new Float(total));

        // marshal object back out to file (with nice indentation, as UTF-8)
        IMarshallingContext mctx = bfact.createMarshallingContext();
        mctx.setIndent(2);
        FileOutputStream out = new FileOutputStream("c:\\out.xml");
        mctx.setOutput(out, null);
        mctx.marshalDocument(order);
        System.out.println("Processed order with " +  order.getItemList().size() + " items and total value " + total);

    }
    catch (FileNotFoundException e)
    {
        e.printStackTrace();
        System.exit(1);
    } catch (JiBXException e)
    {
        e.printStackTrace();
        System.exit(1);
    }
}//end main

}//end class

这是我试图编译这个文件的方式和我得到的输出

C:\jibx\tutorial>javac example25\Test.java
example25\Test.java:8: error: package org.jibx.runtime does not exist
import org.jibx.runtime.BindingDirectory;
                   ^
example25\Test.java:9: error: package org.jibx.runtime does not exist
import org.jibx.runtime.IBindingFactory;
                   ^
example25\Test.java:10: error: package org.jibx.runtime does not exist
import org.jibx.runtime.IMarshallingContext;
                   ^ 
example25\Test.java:11: error: package org.jibx.runtime does not exist
import org.jibx.runtime.IUnmarshallingContext;
                   ^
example25\Test.java:12: error: package org.jibx.runtime does not exist
import org.jibx.runtime.JiBXException;
                   ^
example25\Test.java:25: error: cannot find symbol
IBindingFactory bfact = BindingDirectory.getFactory(Order.class);
        ^
symbol:   class IBindingFactory
location: class Test
 example25\Test.java:25: error: cannot find symbol
 IBindingFactory bfact = BindingDirectory.getFactory(Order.class);
                                ^
 symbol:   variable BindingDirectory
 location: class Test
 example25\Test.java:26: error: cannot find symbol
        IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
        ^
 symbol:   class IUnmarshallingContext
 location: class Test
 example25\Test.java:40: error: cannot find symbol
        IMarshallingContext mctx = bfact.createMarshallingContext();
        ^
 symbol:   class IMarshallingContext
 location: class Test
 example25\Test.java:52: error: cannot find symbol
    } catch (JiBXException e)
             ^
 symbol:   class JiBXException
 location: class Test
 10 errors

Test 使用的所有类文件都在它旁边,并且已经正确编译。测试是给我带来麻烦的最后一个文件。此外,测试中使用的一些类存在于 C:\jibx\lib> 中,而不是我正在执行命令的 C:\jibx\tutorial> 中。任何关于我如何在不修改我以前生成的类文件的情况下解决此问题的建议将不胜感激。

4

2 回答 2

0

由于存在一些导入错误,请按照 Satya 所说正确设置类路径,并且您当前在某个目录中的类您应该使用 javac 的 -d 属性对其进行编译,如下所示

爪哇 -d 。你的文件名.java

于 2012-05-07T04:34:53.253 回答
0

将目录 C:\jibx\lib 添加到您的类路径,例如

SET CLASSPATH=%CLASSPATH%;C:\jibx\lib;.

然后做一个javac

于 2012-05-07T04:28:38.987 回答