Jython和JyNI的研究

本文详细记录了在Linux Mint Debian Edition 13, Ubuntu 13.10和PowerLinux(RedHat)上编译和使用JyNI与Jython2.7b1的过程,包括遇到的问题和解决方法。在Ubuntu 13.10上成功编译并运行示例,但在PowerLinux上由于IBM Java的支持问题导致执行异常。" 106032615,8818170,Python计算最大公约数与最小公倍数,"['Python编程', '数学运算', '算法实现']
摘要由CSDN通过智能技术生成

Linux Mint Debian Edition13(64)

Environment

Sunjdk1.7

Python2.7.3

Jython2.7b1

JyNI.alpha.2

编译JyNI.alpha.2是出错(系统库不兼容)

In file included from /usr/include/string.h:159:0,

                 from ./JyNI-C/include/Python_JyNI/Python_JyNI.h:94,

                 from ./JyNI-C/include/JyNI.h:58,

                 from JyNI-C/src/abstract.c:49:

/usr/include/xlocale.h:39:4: error: declaration for parameter ‘__locale_t’ but no such parameter

In file included from ./JyNI-C/include/Python_JyNI/Python_JyNI.h:94:0,

                 from ./JyNI-C/include/JyNI.h:58,

                 from JyNI-C/src/abstract.c:49:

/usr/include/string.h:150:15: error: declaration for parameter ‘strxfrm’ but no such parameter

/usr/include/string.h:147:12: error: declaration for parameter ‘strcoll’ but no such parameter

/usr/include/string.h:143:12: error: declaration for parameter ‘strncmp’ but no such parameter

/usr/include/string.h:140:12: error: declaration for parameter ‘strcmp’ but no such parameter

/usr/include/string.h:136:14: error: declaration for parameter ‘strncat’ but no such parameter

/usr/include/string.h:133:14: error: declaration for parameter ‘strcat’ but no such parameter

/usr/include/string.h:128:14: error: declaration for parameter ‘strncpy’ but no such parameter

/usr/include/string.h:125:14: error: declaration for parameter ‘strcpy’ but no such parameter

/usr/include/string.h:92:14: error: declaration for parameter ‘memchr’ but no such parameter

/usr/include/string.h:65:12: error: declaration for parameter ‘memcmp’ but no such parameter

/usr/include/string.h:62:14: error: declaration for parameter ‘memset’ but no such parameter

/usr/include/string.h:54:14: error: declaration for parameter ‘memccpy’ but no such parameter

/usr/include/string.h:46:14: error: declaration for parameter ‘memmove’ but no such parameter

/usr/include/string.h:42:14: error: declaration for parameter ‘memcpy’ but no such parameter

JyNI-C/src/abstract.c:2801:1: error: expected ‘{’ at end of input

make: *** [JyNI-C/src/abstract.o] Error 1

 

使用官方提供的jyni-loader.so jyni.so jyni.jar 不起作用

Ubuntu13.10(64bit)

OpenJdk1.7

Python2.7.3 (python dev source)

Jython2.7b1

JyNI.alpha.2

编译可以成功 jyNIsrc/build生成jyni-load.so jyni.so jyni.jar, DemoExtension.so

Jython+jyNI调用DemoExtension

java -cp jython.jar:build/JyNI.jar org.python.util.jython JyNI-Demo/src/JyNIDemo.py

Cpython输出一样(其他两个alpha2可以通过,alpha1不能通过)(输出和Powerlinux环境Cpython一样,不再展示)

在java 应用程序也可调用

调用代码若下

/home/modules:scripts为(/root/workspace/JavaCallPython/natvielib

目录内有编译好的(DemoExtension.so(这是cpython实验扩展部分)  (libJyNI-Loader.so  libJyNI.so)(这是jynic部分)

import java.io.ByteArrayOutputStream;

import java.io.UnsupportedEncodingException;

import java.util.List;

 

import org.python.core.PySystemState;

import org.python.util.PythonInterpreter;

public class SecondJavaScript

{

 

public static void main(String args[])

 {

  

  PythonInterpreter interpreter = new PythonInterpreter();

  Properties props = new Properties();
       props.setProperty("python.path", "/home/modules:scripts");
      PythonInterpreter.initialize(System.getProperties(), props,
                                   new String[] {
     ""});

 

  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

 

  ByteArrayOutputStream errorStream = new ByteArrayOutputStream();

  interpreter.setOut(outputStream);

  interpreter.setErr(errorStream);

  PySystemState sys = interpreter.getSystemState();

 

 

 

//  interpreter.exec("import sys;sys.path.append('C:/jython2.7b1/Lib/site-packages')");

 // interpreter.exec("import sys;sys.path.append('C:/jython2.7b1/Lib&#

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值