2012-05-07 68 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 

感谢您的精彩建议