从外部库导入 jython

发布于 2024-07-19 03:22:30 字数 563 浏览 1 评论 0原文

我正在尝试从 jyhon 中的外部库导入 java 类,但它不起作用。 一个例子

package run;
    import import.Imported;
    Class Run()
    {
        public static void main(String[] args){
                 pi = new PythonInterpreter(null);
        pi.execfile('script.py');
            }
    }
    //this is an external libary
    package import;
    Class Imported()
    {
         //some stuff;
    }

   //py script
   from import import Imported //this line throws an error Module not found
   #do some stuff

最奇怪的是它在 Eclipse 中编译时运行,但不是从命令行运行。 有什么帮助吗?

I am trying to imported a java class from an external lib in jyhon and it does not work. An example

package run;
    import import.Imported;
    Class Run()
    {
        public static void main(String[] args){
                 pi = new PythonInterpreter(null);
        pi.execfile('script.py');
            }
    }
    //this is an external libary
    package import;
    Class Imported()
    {
         //some stuff;
    }

   //py script
   from import import Imported //this line throws an error Module not found
   #do some stuff

The strangest thing is that it runs when it is compiled in Eclipse, but does not from command line.
Any help?

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

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

发布评论

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

评论(1

如梦亦如幻 2024-07-26 03:22:30

听起来您的类路径可能在运行时设置不正确。 最简单的解决方案通常是将包含“import”的目录或 jar 文件添加到 sys.path。

(另外,将你的包命名为“import”只是自找麻烦。)

Sounds like your classpath is probably set incorrectly at runtime. The easiest solution is typically just to add the directory or jar file containing 'import' to sys.path.

(Also, naming your packages 'import' is just asking for trouble.)

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