Why does Jython refuse to find my Java package?

前端 未结 3 1907
鱼传尺愫
鱼传尺愫 2020-12-17 17:09

I know it\'s something silly, but for some reason Jython refuses to find javax.swing. I\'m using Java 1.6.0_11. This is my start-up script:

@echo off

\"%J         


        
3条回答
  •  囚心锁ツ
    2020-12-17 17:56

    I had similar issues, and it turns out that since the standalone Jython dist does not support caching, it also does not support the "import *" approach. This is not clearly documented anywhere in the official Jython docs, but I concluded this based on a number of different bug reports:

    • https://groups.google.com/forum/?hl=en&fromgroups=#!topic/robotframework-users/6ipB0DYJkvU
    • http://bugs.jython.org/issue1778514
    • http://bugs.jython.org/issue1422
    • http://bugs.jython.org/issue1692579

    Notable from that last link:

    So as Oti noted, in standalone you must do full imports to succeed.

    To fix your issue, use the non-standalone standard jython.jar generated by installing jython using the 'Standard' option.

    If you wanted to package and distribute jython.jar with your application, in case a user does not have Jython installed, then you will also need to copy/pase the complete "Lib" folder from the jython installation directory into whichever location you end up placing jython.jar. This enables access to the python stdlib which is not included in the standard jar file.

    UPDATE: After playing around more, I think I have a fix to enable "import *" type imports even when using the standalone jar. All that needs to be done is to enable caching!

    You can do this by either adding the following options to the jvm when running jython:

    -Dpython.cachedir.skip=false -Dpython.cachedir=DESIRED CACHE PATH

    (Note that the second argument is optional, and if left blank, a default value will be used)

    If you are having an issue running the InteractiveConsole embedded in an app (which is what my problem was) you can add these properties before initializing the console:

        Properties props = new Properties();
        props.put("python.cachedir.skip", "false");
        props.put("python.cachedir", "DESIRED CACHE PATH"); // again, this option is optional
        InteractiveConsole.initialize(System.getProperties(), props, new String[0]);
    

提交回复
热议问题