2012-05-07 5 views
1

を私はファイルをバインドするために管理し、正常XSDを介して生成し、私は私のディレクトリに次のファイルは、あなたのコード内のバインドさクラスを使用する - JiBXの

C:\jibx\tutorial\example25>dir 
Volume in drive C is WINDOWS 
Volume Serial Number is 1C8F-663E 

Directory of C:\jibx\tutorial\example25 

05/06/2012 07:12 PM <DIR>   . 
05/06/2012 07:12 PM <DIR>   .. 
05/06/2012 07:12 PM    3,313 Address.class 
05/06/2012 07:08 PM    3,447 Address.java 
05/06/2012 07:10 PM    2,912 binding.xml 
05/06/2012 07:12 PM    2,516 Customer.class 
05/06/2012 07:08 PM    1,763 Customer.java 
05/06/2012 07:12 PM    2,582 Item.class 
05/06/2012 07:08 PM    1,878 Item.java 
05/06/2012 07:12 PM    2,529 JiBX_bindingFactory.class 
05/06/2012 07:12 PM    2,384 JiBX_bindingMungeAdapter.class 
05/06/2012 07:12 PM    2,490 JiBX_bindingOrder_access.class 
05/06/2012 07:12 PM    7,539 Order.class 
05/06/2012 07:09 PM    4,869 Order.java 
05/06/2012 07:11 PM    1,034 Shipping.class 
05/06/2012 07:09 PM    879 Shipping.java 
05/06/2012 12:22 AM    5,137 starter.xsd 
      15 File(s)   45,272 bytes 
      2 Dir(s) 160,023,375,872 bytes free 

が、今私は中に新しく作成されたJavaプロジェクトにこれらのファイルをコピーしました日食、そのプロジェクトに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; 
import example25.*; 


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 

を、それを実行した

Unable to access binding information for class example25.Order 
Make sure the binding has been compiled 
java.lang.NoSuchFieldException: JiBX_bindingList 
at java.lang.Class.getDeclaredField(Unknown Source) 
at org.jibx.runtime.BindingDirectory.getBindingList(BindingDirectory.java:68) 
at org.jibx.runtime.BindingDirectory.getFactory(BindingDirectory.java:211) 
at Test.main(Test.java:24) 

答えて

2

ラジェッシュ、

あなたがそのディレクトリに表示されたファイルはすべて正しくをした意味します!

あなたが作った間違いを自動的に日食が(あなたが結合手順で追加したバインディング情報なし)、再びソースコードファイルをコンパイルするので、Eclipseを使用していた

クラスファイルをご提出Test.classを実行してみてください最初のステップで生成されます。

あなたのjavaコマンドは次のようなものでなければなりません:

java -cp C:\directorywithtestclass;C:\jibx\tutorial Test 

ドン

1

JiBXのバインディングコンパイラは、生成されたクラスファイルを変更し、binding.xmlを使用してバインディング情報を置きますので、我々はバインディングを使用する必要がありますので、コンパイラを使用して、生成された.javaファイルとbinding.xmlからクラスファイルを生成します。これを行うためにeclipseを使用するには、this linkで説明されているように使用できます。

関連する問題