简体   繁体   English

从外部lib jython导入

[英]import from external lib jython

I am trying to imported a java class from an external lib in jyhon and it does not work. 我试图从jyhon的外部库中导入一个Java类,但是它不起作用。 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. 最奇怪的是,它是在Eclipse中编译时运行的,而不是从命令行运行的。 Any help? 有什么帮助吗?

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. 最简单的解决方案通常是将包含“导入”的目录或jar文件添加到sys.path。

(Also, naming your packages 'import' is just asking for trouble.) (此外,将包命名为“ import”只是在麻烦。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM