使用jython时java.nio.charset.UnsupportedCharsetException

时间:2019-04-28 15:39:18

标签: spring spring-boot jython-2.7

我想创建一个函数来解释Java中的Python代码,但是当我使用Jython时,会遇到此异常。

我的代码如下。

PythonInterpreter interp = null;
        try{
            System.out.println("hello");
            Properties p = new Properties();
            p.setProperty("python.path", "C:/Users/.../.m2/repository/org/python/jython/2.7.0");
            p.setProperty("python.home", "C:/Users/.../.m2/repository/org/python/jython/2.7.0");
            p.setProperty("python.prefix", "C:/Users/.../.m2/repository/org/python/jython/2.7.0");
            PythonInterpreter.initialize(System.getProperties(), p, new String[] {});
            interp = new PythonInterpreter();
        }catch(Exception ex){
            ex.toString();
            //Log("Exception while creating python interpreter: "+ex.toString());
        }

        // The exec() method executes strings of code
        interp.exec("import sys");
        interp.exec("print sys");

这是我的专家:

<dependency>
            <groupId>org.python</groupId>
            <artifactId>jython</artifactId>
            <version>2.7.0</version>
        </dependency>
        <dependency>
            <groupId>org.python</groupId>
            <artifactId>jython-standalone</artifactId>
            <version>2.7.0</version>
        </dependency>

这是我在执行此代码时遇到的异常:

console: Failed to install '': java.nio.charset.UnsupportedCharsetException: cp0.
2019-04-28 16:33:11.459 ERROR 18008 --- [nio-8081-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause

java.lang.NullPointerException: null
    at com.oracle.services.ServicesImpl.extractPythonCode(ServicesImpl.java:37) ~[classes/:na]
    at com.oracle.controller.EndPointController.excute(EndPointController.java:23) ~[classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181

0 个答案:

没有答案