我们有一个庞大的Java项目,并决定将其中一部分移植到.NET(GUI等)。为了加快进程,我们使用IKVM(JVM for .NET)。在大多数情况下它工作正常但是当我到达Jython代码然后它被卡住然后抛出异常java.lang.NoSuchMethodException
和PyException
之后。它发生在方法PythonInterpreter.interpreter.exec
中。
即使是简单的例子:
爪哇:
class Main {
public static String printIt() {
PythonInterpreter pi = new PythonInterpreter();;
pi.set("integer", new PyInteger(122));
pi.exec("result = integer * integer");
pi.exec("print('hello!')");
return "hello";
}
}
C#:
var code = Main.printIt();
什么限制或限制导致例外?一般来说,在哪里可以找到IKVM的所有限制(已经搜索了很多,没有找到与此案例相关的内容)。感谢。
更新 使用IKVM 8.1和jython-standalone-2.5.3,JDK 1.8,.NET 4.5
这是一个堆栈跟踪:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "src_python\Util.py", line 2, in <module>
from com.trueship.jyinterface import PyUtil
File "src_python\Util.py", line 2, in <module>
from com.trueship.jyinterface import PyUtil
java.lang.NoClassDefFoundError: junit.framework.TestCase
at Java_java_lang_ClassLoader.defineClass1(Unknown Source)
at IKVM.Internal.AssemblyClassLoader.DefineDynamic(Unknown Source)
at IKVM.Internal.AssemblyClassLoader.LoadDynamic(Unknown Source)
at IKVM.Internal.AssemblyClassLoader.LoadClassImpl(Unknown Source)
...
at org.python.core.Py.runCode(Py.java:1275)
at org.python.core.Py.exec(Py.java:1319)
at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:207)
at com.trueship.jyinterface.Jyb.findClass(Jyb.java:113)
at com.trueship.jyinterface.Jyb.initUtil(Jyb.java:90)
at com.trueship.jyinterface.Jyb.<init>(Jyb.java:77)
at com.trueship.jyinterface.Jyb.getInstance(Jyb.java:102)
at com.trueship.cordage.orders.JSONOrderParser.parseOrder(JSONOrderParser.java:41)
at com.trueship.cordage.readycloud.ReadyCloudApiClient.getOrders(ReadyCloudApiClient.java:302)
at com.trueship.cordage.readycloud.ReadyCloudApiClient.downloadOrders(ReadyCloudApiClient.java:264)
at cli.ReadyShipper.Windows.MainWindow.DownloadOrders(MainWindow.xaml.cs:75)
at cli.ReadyShipper.Windows.MainWindow.<.ctor>b__1(MainWindow.xaml.cs:49)
at cli.System.Windows.RoutedEventHandlerInfo.InvokeHandler(Unknown Source)
at cli.System.Windows.EventRoute.InvokeHandlersImpl(Unknown Source)