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)(这是jyni的c部分)
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&# |