jpythonµ÷ÓÃjavaÀàµÄÄ£°å
ʹÓÃJPypeÄ£¿éÈÃPythonµ÷ÓÃJAVAµÄÀà
Python idea! 2009-03-24 19:44 ÔĶÁ267 ÆÀÂÛ0
×ֺţº ´ó´ó ÖÐÖРСС
¿´¿´Àý×Ó¾ÍÖªµÀÀ²£¬ÕæÊÇΪPython£¨²»ÊÇJython£¬¶øÊÇCPython£©ÌṩÁËÇ¿´óÁ¦Á¿£¡
Ê×ÏÈÔÚjavaϽ¨Á¢Ò»¸öÔÙÒ²¼òµ¥²»¹ýµÄ°ü£º
package org.wg3i.test;
class Test {
private String msg;
public Test() {
}
public void speak(String msg) {
System.out.println(msg);
}
public void setString(String s) {
msg = s;
}
public String getString() {
return msg;
}
}
ÔÚPythonÏÂʹÓÃJPypeÄ£¿éÀ´µ÷ÓÃÎÒÃǸոÕÉú³ÉµÄjava°ü£º
import jpype
import os.path
jarpath = os.path.join(os.path.abspath('.'), 'build/jar')
jpype.startJVM(jpype.getDefaultJVMPath(), "-Djava.ext.dirs=%s" % jarpath)
Test = jpype.JClass('org.wg3i.test.Test') # È¡µÃ°üorg.wg3i.testÖеÄÀàTest
t = Test() # ´´½¨TestʵÀý
t.speak("This is a test message") # ³¢ÊÔµ÷ÓÃÀàµÄÒ»¸ö·½·¨
t.setString("Hello, World") #¸ø¶¨String
s = t.getString() # »ñÈ¡String
print s
jpype.shutdownJVM()
ÏÂÃæÀ´½éÉÜÏÂÈçºÎµ÷Óðü¶ø²»ÊǾßÌåµÄÒ»¸öÀࣺ
import jpype
import os.path
classpath = os.path.join(os.path.abspath('.'), 'build/classes')
jpype.startJVM(jpype.getDefaultJVMPath(), "-Djava.class.path=%s" % classpath)
testPkg = jpype.JPackage('org').wg3i.test # È¡µÃ°ü
Test = testPkg.Test # È¡µÃÀà
t = Test() # ´´½¨TestʵÀý
t.speak("This is a test message") # ³¢ÊÔµ÷ÓÃÀàµÄÒ»¸ö·½·¨
t.setString("Hello, World") &nbs
Ïà¹ØÎĵµ£º
1.//propertyÎļþµÄ¶ÁÈ¡
//com.test.messageÎļþ
package com.test;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
public class Test_Messages {
private static final String BUNDLE_NAME = "com.test.messages";
private static final ResourceBundle RESOURCE_BUNDLE = Reso ......
/**
*
*/
package com.dongyun.peas2.system.web.action;
///**
// * @author Administrator
// *
// */
//public class ABcom {
//
// /**
// *
// */
// public ABcom() {
// // TODO Auto-generated constructor stub
// }
//
// /**
//&nb ......
¼Ì³Ð(inheritance)
¼Ì³ÐÊÇʹÓÃÒÑ´æÔÚµÄÀàµÄ¶¨Òå×÷Ϊ»ù´¡½¨Á¢ÐÂÀàµÄ¼¼Êõ£¬ÐÂÀàµÄ¶¨Òå¿ÉÒÔÔö¼ÓеÄÊý¾Ý»òÐµĹ¦ÄÜ£¬Ò²¿ÉÒÔÓø¸ÀàµÄ¹¦ÄÜ£¬µ«²»ÄÜÑ¡ÔñÐԵؼ̳и¸Àà¡£ÕâÖÖ¼¼ÊõʹµÃ¸´ÓÃÒÔǰµÄ´úÂë·Ç³£ÈÝÒ×£¬Äܹ»´ó´óËõ¶Ì¿ª·¢ÖÜÆÚ£¬½µµÍ¿ª·¢·ÑÓᣱÈÈç¿ÉÒÔÏȶ¨ÒåÒ»¸öÀà½Ð³µ£¬³µÓÐÒÔÏÂÊôÐÔ£º³µÌå´óС£¬ÑÕÉ ......
ϵͳÊôÐÔÊÇÖ¸ÓëÓû§³ÌÐòÏà¹ØµÄ²Ù×÷ϵͳÅäÖÃÐÅÏ¢ÒÔ¼°Èí¼þÐÅÏ¢¡£Í¨³£ÓëÓû§³ÌÐòÏà¹ØµÄÊôÐԹؼü×Ö°üÀ¨£º
¡¡¡¡¡ñfile.separator:Îļþ·Ö¸ô·û£¬Windows»·¾³ÏÂΪ“"£¬Unix»·¾³ÏÂΪ“/”£»
¡¡¡¡¡ñuser.home£ºÓû§Ö÷Ŀ¼£»
¡¡¡¡¡ñjava.home£ºJavaʵʱÔËÐл·¾³µÄ°²×°Ä¿Â¼£»
¡¡¡¡¡ñjava.ext.dirs£ºJDKµÄ°²×°Ä¿ ......