2012-05-07 65 views
1

我有以下目錄結構 C:\ JiBX的\教程\ example23 \ 的例子23包含以下文件難度用javac編譯 - 問題

enter image description here

現在我試圖編譯的CustomerManager的java文件只它引用了的CustomerManager的java文件,這folder.The代碼其它類是直接

package example23; 

import java.io.FileInputStream; 
import java.io.FileNotFoundException; 
import java.io.FileOutputStream; 
import org.jibx.runtime.*; 

public class CustomerManager 
{ 

       public CustomerManager() 
       { 
      try 
      { 
      IBindingFactory bfact = BindingDirectory.getFactory(Customer.class); 
      IUnmarshallingContext uctx = bfact.createUnmarshallingContext(); 

      Object obj = uctx.unmarshalDocument(new FileInputStream("C:/jibx/tutorial/example23/customer.xml"), null); 
      Customer customer = (Customer)obj; 
      System.out.print(customer.street+", "+customer.city); 
      IMarshallingContext mctx = bfact.createMarshallingContext(); 
      mctx.setIndent(4); 
      mctx.marshalDocument(obj, "UTF-8", null, new FileOutputStream("C:/jibx/tutorial/example23/customer2.xml")); 
      } 
      catch (FileNotFoundException e) 
      { 
      e.printStackTrace(); 
      } 
      catch (JiBXException e) 
      { 
      e.printStackTrace(); 
      } 
        } //end method 

public static void main(String[] args) 
{ 
new CustomerManager(); 
} 

}//end class 

現在這個文件包含在我的文件引用TS頂部目錄,如C:\的JiBX \ lib中(該文件本身是在C:\的JiBX \教程\ example23)

我嘗試以下引用這些庫和編譯文件

C:\jibx\tutorial>javac -classpath c:\jibx\lib\ example23\CustomerManager.java 

and the output i got was 
example23\CustomerManager.java:7: error: package org.jibx.runtime does not exist 

import org.jibx.runtime.*; 
^ 
example23\CustomerManager.java:16: error: cannot find symbol 
           IBindingFactory bfact = BindingDirectory.getFactory(Customer.class); 
           ^
symbol: class IBindingFactory 
location: class CustomerManager 
example23\CustomerManager.java:16: error: cannot find symbol 
          IBindingFactory bfact = BindingDirectory.getFactory(Customer.class); 

^
symbol: class Customer 
location: class CustomerManager 
example23\CustomerManager.java:16: error: cannot find symbol 
           IBindingFactory bfact = BindingDirectory.getFact 
ory(Customer.class); 
                ^
symbol: variable BindingDirectory 
location: class CustomerManager 
example23\CustomerManager.java:17: error: cannot find symbol 
          IUnmarshallingContext uctx = bfact.createUnmarsh 
allingContext(); 
          ^
symbol: class IUnmarshallingContext 
location: class CustomerManager 
example23\CustomerManager.java:20: error: cannot find symbol 
          Customer customer = (Customer)obj; 
          ^
symbol: class Customer 
location: class CustomerManager 
example23\CustomerManager.java:20: error: cannot find symbol 
          Customer customer = (Customer)obj; 
               ^
symbol: class Customer 
location: class CustomerManager 
example23\CustomerManager.java:22: error: cannot find symbol 
          IMarshallingContext mctx = bfact.createMarshalli 
ngContext(); 
          ^
symbol: class IMarshallingContext 
location: class CustomerManager 
example23\CustomerManager.java:30: error: cannot find symbol 
          catch (JiBXException e) 
           ^
symbol: class JiBXException 
location: class CustomerManager 
9 errors 

C:\jibx\tutorial> 

有關我如何解決這個問題的任何建議?

+0

昨天你也有同樣的問題,這個論壇建議您糾正你的classpath。在繼續進行之前,您能否請嘗試查看PATH/CLASSPATH? – Satya

+0

是的,我確實看過他們這就是爲什麼我開始另一個職位。我打算回覆這些帖子,但AddComment部分並不真的有幫助 – Rajeshwar

回答

3

您必須在您的classpath中添加.jar文件。

例如,

javac -cp .;c:\jibx\lib\your_lib.jar example23\CustomerManager.java 
+0

is -cp是-classpath的縮寫嗎?我們可以用-cp來代替嗎? – Rajeshwar

+0

是的!看看我發佈的鏈接。 – adatapost

+0

所以這裏是我得到的 - 使用的命令:C:\ jibx \ tutorial \ example23> javac -cp。; c:\ jibx \ lib \ org.eclipse.core.runtime.jar CustomerManager.java輸出的一部分: CustomerManager.java:7:錯誤:包org.jibx.runtime不存在import org.jibx.runtime。*; ^是否有可能是javac解決導入時帶*的問題? – Rajeshwar

5

你的問題出在下面的行我認爲

-classpath c:\jibx\lib\ 

是否該目錄包含的jar文件?

在這種情況下,你可以嘗試使用水珠,像這樣:

-classpath c:\jibx\lib\*.jar 

這樣,您將包括在C中的所有jar文件:\的JiBX \ LIB \在你的類路徑目錄。

+0

是的lib文件是在第一個,我嘗試使用*。罐子的風格,但這不工作 – Rajeshwar

+0

這裏是我得到的輸出[鏈接](http://i1076.photobucket.com/albums/w459/rajeshkhan808/output.png) – Rajeshwar

+0

任何想法我失蹤? – Rajeshwar

0

我設法解決這個問題:

C:\jibx\tutorial>javac -cp .\example23\*;.;.;c:\jibx\lib\jibx-run.jar; .\example23\CustomerManager.java 

感謝您的精彩建議