如何在.java文件中导入.class文件? [英] How to import .class file in a .java file?

查看:959
本文介绍了如何在.java文件中导入.class文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要做的是如下:


  1. 我有一个bigloo方案程序(* .scm)使用bigloo框架jvm生成一个类文件。

  1. I have a bigloo scheme program (*.scm), then using the bigloo frameworks jvm a class file is generated.

我想使用.java文件中的.class文件。也就是说,我需要导入这个(.class)文件,因为我想使用现在是.class文件的方案文件中定义的一些函数。

I want to use this .class file from a .java file. That is, i need to import this(.class) file as i want to use some functions defined in the scheme file which is now a .class file.

如何在Eclipse中执行此操作?我已经为java创建了两个包,一个用于.class文件。然后我导入包含.class文件的包。但是我不能在.java文件中的.class文件中使用该函数。是否有任何设置?

How do i do it in Eclipse? i have created two packages one for java and one for the .class file. Then i import the package containing the .class file. But i am not able to use the function in the .class file in the .java file. Are there any settings to be done?

请让我知道如何做到这一点。

Please let me know how this can be done.

推荐答案

您可以通过右键单击项目将包含编译类的文件夹添加到项目中,然后选择属性>Java构建路径,然后添加外部类文件夹

You can add a folder containing compiled classes to your project by right clicking the project, then select Properties > Java build path, then "Add External Class Folder"

如果已经将类文件复制到项目的子目录中,请选择添加类文件夹。

Or choose "Add Class Folder" if you have copied the class files into a sub directory of your project.

这将把类文件添加到项目类路径中,然后可以使用import语句将类导入到java文件中:

This will add the class files to the projects classpath and you can then import the class into your java file using an import statement:

import my.package.MyClass;

注意:包装结构应保留在您添加的文件夹下作为一个类文件夹。所以如果你添加文件夹myclasses作为一个类文件夹,目录结构应如下所示:

Note: The package structure should be maintained under the folder that you add as a class folder. So if you add folder "myclasses" as a class folder, the directory structure should be as follows for the example above:

myclasses / my / package / MyClass.class

myclasses/my/package/MyClass.class

这篇关于如何在.java文件中导入.class文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆