Jython won't import user-defined class; ImportError: No module named ******

后端 未结 2 1593
孤城傲影
孤城傲影 2021-01-04 20:07

I\'ve been banging my head against the wall for a couple days now trying to figure this out. I\'ve been starting to play around with Jython for fast prototyping. I\'ve hit w

2条回答
  •  伪装坚强ぢ
    2021-01-04 20:47

    I think there may be an error in that example. When you import X in Jython, this looks for a Java package named X, not for a class named X.

    Try:

    // Beach.java
    package com.stackoverflow.beach;
    
    public class Beach {
        private String name;
        ...
    

    and in Jython:

    from com.stackoverflow.beach import Beach
    bondi = Beach("Bondi Beach", "Sydney")
    

    edit: Also, you might want to make sure that the full name of the .jar file -- and not just the directory where it resides -- is listed on the CLASSPATH. This is certainly necessary in Java, and I assume Jython's rules are the same in this regard.

提交回复
热议问题