使用 .class 文件而不是 jar 将 Java 类导入 Jython

发布于 2024-12-15 13:56:01 字数 756 浏览 0 评论 0原文

我已经搜索了一段时间,似乎找不到这个问题的答案。是否可以将用户定义的 .class 文件直接导入到 Jython 中而不是 .jar。我想使用 Jython 来测试我用 java 编写的文件(如果这会改变任何内容,我将使用 Netbeans)。我打算最终使用 Jython 作为脚本语言(它将是一个游戏)和主循环代码。但现在,我什至无法让 Jython 导入我的 .class 文件,而且我真的不想每次我想测试代码或尝试某些东西时都必须将所有内容都变成 .jar...

我已经添加了文件夹包含 sys.path 和 classpath 中的所有 .class 文件。当我尝试导入包('x86Wars'...'因为它基于用于 Gameboy Advance 的 Advance Wars...)时,它给了我:

Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
ImportError: No module named x86Wars

但是当我尝试直接导入 .class 文件名时(我实际上已经添加了包含 .java 源和 .class 的文件夹),它给了我:

java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: FullScreenDisplay (wrong name: x86Wars/FullScreenDisplay)

任何帮助将不胜感激!

I've been searching for a while and cannot seem to find an answer to this problem. Is it possible to import a user-defined .class file into Jython directly without it being a .jar. I want to use Jython to test files I'm writing in java (I'm using Netbeans if this changes anything). I intend to eventually use Jython as both a scripting language (it's going to be a game) and for the main loop code. But for now, I cannot even get Jython to import my .class files, and I really do not want to have to make everything a .jar each time I want to test the code or try something...

I have already added the folder containing all the .class files to both sys.path and classpath. When I try importing the package ('x86Wars'...'cause it's based on Advance Wars which was for the Gameboy Advance...) it gives me:

Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
ImportError: No module named x86Wars

But when I try importing the .class file name directly (I have actually added both the folder containing the .java source and the .class one), it gives me:

java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: FullScreenDisplay (wrong name: x86Wars/FullScreenDisplay)

Any help would be greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

守望孤独 2024-12-22 13:56:02

确保文件夹正确模仿包名称?从你添加到 python 路径(和类路径)的根目录开始,你必须为 com.game.x86wars 的每个点名称都有一个文件夹,你应该有 /com/game/x86wars/class.class

Are sure the folders mimick the package name correctly? From the root youi have added to the python path (and classpath), you must have one folder for each dotted name for com.game.x86wars you should have /com/game/x86wars/class.class

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文