jEdit+JythonInterpreter:如何导入java类?

发布于 2024-09-02 21:31:31 字数 690 浏览 3 评论 0原文

我正在使用 JythonInterprete 运行 jEdit,并且有一个名为 JavaTest.jar 的 .jar 文件。

JavaTest 有一个名为 SampleJavaClass 的类,它有一个 PrinterCount 方法。

从我的 .py 文件中,我想做:

from javatest import SampleJavaClass

class SampleClass(SampleJavaClass):
 def pymain(self):
  SampleJavaClass.printerCount(4)

Java 代码:

package javatest;


public class SampleJavaClass {


    public static void printerCount(int i){
        for(int j=0; j< i; j++){
            System.out.println("hello world");
        }
    }
(etc...)

在 JythonInterpreter 中,我已经尝试单击“编辑 Jython 路径”并添加 .jar 文件,然后再次运行解释器,但它仍然给我 ImportError:无法导入名称 SampleJavaClass

I'm running jEdit with the JythonInterprete and I have a .jar file called JavaTest.jar.

JavaTest has a class called SampleJavaClass which has a method printerCount.

From my .py file, I want to do:

from javatest import SampleJavaClass

class SampleClass(SampleJavaClass):
 def pymain(self):
  SampleJavaClass.printerCount(4)

Java code:

package javatest;


public class SampleJavaClass {


    public static void printerCount(int i){
        for(int j=0; j< i; j++){
            System.out.println("hello world");
        }
    }
(etc...)

In the JythonInterpreter, I have already tried clicking "Edit Jython Path" and adding the .jar file then running the interpreter again, but it still gives me ImportError: cannot import name SampleJavaClass

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

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

发布评论

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

评论(1

梦过后 2024-09-09 21:31:31

您需要将 JavaTest.jar 添加到 jEdit 使用的 Java 类路径中。 Jython 路径用于告诉 Jython Python 模块在哪里,Java 类路径用于告诉 JVM Java jar 在哪里。为了访问 Jython 中的 javatest.SampleJavaClass,JVM 必须首先能够找到它。然后它将使其可供 Jython 解释器使用,并且您的代码应该运行。

我不太熟悉如何在 jEdit 中设置 JVM 类路径,但我确实找到了 这个维基页面可能包含答案。

You need to add the JavaTest.jar to the Java classpath used by jEdit. The Jython path is used to tell Jython where the Python modules are, the Java classpath is used to tell the JVM where the Java jars are. In order to access javatest.SampleJavaClass in Jython the JVM must first be able to find it. It will then make it available to the Jython interpreter and your code should run.

I'm not that familiar with how to set the JVM classpath in jEdit but I did find this wiki page which may hold the answer.

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