使用Javac编译困难-问题

使用Javac编译困难-问题,java,compilation,Java,Compilation,我有以下目录结构 c:\jibx\tutorial\example23\ 示例23包含以下文件 现在,我试图编译CustomerManager java文件,该文件只引用该文件夹中的其他类 package example23; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import org.jibx.runtime.*; pub

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

现在,我试图编译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>

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

您必须在数据库中添加.jar文件

比如说,

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

您必须在应用程序中添加.jar文件

比如说,

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

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

-classpath c:\jibx\lib\
这个目录包含jar文件吗

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

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

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

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

-classpath c:\jibx\lib\
这个目录包含jar文件吗

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

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

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

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

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

感谢您的宝贵建议

我通过以下方式解决了问题:

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


感谢您昨天提出的宝贵建议

您也遇到了同样的问题,本论坛建议您更正课程路径。在继续之前,你能试着看一看路径/类路径吗?是的,我确实看了它们,这就是为什么我开始另一篇文章的原因。我本来打算回复那些帖子的,但是AddComment部分没有真正的帮助,昨天你也遇到了同样的问题,这个论坛建议你纠正你的类路径。在继续之前,你能试着看一看路径/类路径吗?是的,我确实看了它们,这就是为什么我开始另一篇文章的原因。我本来打算回复那些帖子的,但是AddComment部分并没有真正的帮助,-cp是-classpath的缩写吗?我们可以用-cp来代替吗?是的!看看我发布的链接,下面是我得到的-使用的命令:C:\jibx\tutorial\example23>javac-cp。;c:\jibx\lib\org.eclipse.core.runtime.jar CustomerManager.java输出的一部分:CustomerManager.java:7:错误:包org.jibx.runtime不存在导入org.jibx.runtime.*;^javac是否有可能在解决带有*的导入时遇到问题?下面是我得到的输出,我设法减少了错误。现在,它只需要指向正在使用的类文件的路径,我已经用“cp”提供了这个路径?我们可以用-cp来代替吗?是的!看看我发布的链接,下面是我得到的-使用的命令:C:\jibx\tutorial\example23>javac-cp。;c:\jibx\lib\org.eclipse.core.runtime.jar CustomerManager.java输出的一部分:CustomerManager.java:7:错误:包org.jibx.runtime不存在导入org.jibx.runtime.*;^javac是否有可能在解决带有*的导入时遇到问题?下面是我得到的输出,我设法减少了错误。现在它只需要指向我已经使用“cp”提供的类文件的路径。图像输出为是,lib文件在第一个文件中,我也尝试使用*.jar样式,但不起作用。这是我得到的输出,我设法减少了错误。现在,它只需要指向正在使用的类文件的路径,我已经通过使用“cp”提供了该路径。图像输出位于。如果您有任何建议,我将不胜感激。您可以发布该Customer.java文件吗?还可以尝试使用powershell运行它,通常最好的方法是使用支持globs(*?)的ANT构建文件。但是powershell应该可以进行测试是的,lib文件在第一个文件中,我也尝试使用*.jar样式,但不起作用。这是我得到的输出,我设法减少了错误。现在,它只需要指向正在使用的类文件的路径,我已经通过使用“cp”提供了该路径。图像输出位于。如果您有任何建议,我将不胜感激。您可以发布该Customer.java文件吗?还可以尝试使用powershell运行它,通常最好的方法是使用支持globs(*?)的ANT构建文件。但是powershell应该可以进行测试