有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

用Javac编译java的困难问题

我有以下目录结构 c:\jibx\tutorial\example23\ 示例23包含以下文件

enter image description here

现在,我试图编译CustomerManager java文件,该文件仅引用此文件夹中的其他类。CustomerManager java文件的代码很简单

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

现在,该文件包含对其顶部目录中文件的引用,如c:\jibx\lib(文件本身位于c:\jibx\tutorial\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>

关于我如何解决这个问题有什么建议吗


共 (3) 个答案

  1. # 1 楼答案

    我认为你的问题在于以下几行

    -classpath c:\jibx\lib\
    

    这个目录包含jar文件吗

    在这种情况下,您可以尝试使用如下glob:

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

    这样,您将在类路径的c:\jibx\lib\目录中包含所有jar文件

  2. # 2 楼答案

    你必须补充。您的classpath中的jar文件

    比如说,

    javac  -cp .;c:\jibx\lib\your_lib.jar  example23\CustomerManager.java
    
  3. # 3 楼答案

    我设法通过以下方式解决了这个问题:

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

    谢谢你的建议