如何在.java 文件中导入.class 文件?
我需要做的是如下:
我有一个bigloo方案程序(*.scm),然后使用bigloo框架jvm生成一个类文件。
我想使用 .java 文件中的这个 .class 文件。也就是说,我需要导入这个(.class)文件,因为我想使用方案文件中定义的一些函数,该文件现在是一个.class文件。
如何在 Eclipse 中执行此操作?我创建了两个包,一个用于 java,另一个用于 .class 文件。然后我导入包含 .class 文件的包。但我无法在 .java 文件中使用 .class 文件中的函数。是否需要进行任何设置?
请告诉我如何做到这一点。
What i need to do is as follows:
I have a bigloo scheme program (*.scm), then using the bigloo frameworks jvm a class file is generated.
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过右键单击项目,然后选择“属性”>“项目”,将包含已编译类的文件夹添加到项目中。 Java 构建路径,然后“添加外部类文件夹”
或者如果您已将类文件复制到项目的子目录中,则选择“添加类文件夹”。
这会将类文件添加到项目类路径中,然后您可以使用 import 语句将该类导入到 java 文件中:
注意: 包结构应保留在您添加为类的文件夹下文件夹。因此,如果您添加文件夹“myclasses”作为类文件夹,则上面示例的目录结构应如下所示:
myclasses/my/package/MyClass.class
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.
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:
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
您可以用它创建一个 jar 并将其添加为库——jar 通常只与 .class 文件一起打包。只需将它们塞入具有正确目录结构和基本文件的 .zip 文件(解压缩另一个 .jar 以查看内部)并重命名为 .jar。您还可以使用官方 jar 工具 - 例如,
jar cvf TicTacToe.jar TicTacToe.class
http://java.sun.com/docs/books/tutorial/deployment/jar/build.html
(来源:sun.com)
You could create a jar out of it and add it as a library -- jars are typically packaged with just the .class files. Just jam them into a .zip file with the correct directory structure and basic files (unzip another .jar to have a look inside) and rename to .jar. You could also use the official jar tool -- e.g.,
jar cvf TicTacToe.jar TicTacToe.class
http://java.sun.com/docs/books/tutorial/deployment/jar/build.html
(source: sun.com)