在从Python发送通知之前,您可以使用一个永不结束的线程创建一个类java程序.
这样lib就可以保存在内存中,并可以从Python程序中访问.
这个类可能是这样的(添加你需要的lib import / init):
public class TestPy {
private Thread thread;
public void die() {
synchronized (thread) {
thread.interrupt();
}
}
public TestPy() {
thread = new Thread(){
public void run() {
try {
while (!Thread.interrupted()) {
Thread.sleep(500);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
};
thread.start();
}
public static void main(String[] args) {
TestPy tp = new TestPy();
GatewayServer server = new GatewayServer(tp);
server.start();
}
}
你必须启动java程序,使用lib,然后使用die()方法杀死Python中的java程序:
gateway = JavaGateway()
do your stuff here using the lib
tp = gateway.entry_point
tp.die()
最后
以上就是稳重宝马最近收集整理的关于java使用python库_使用python中的java库(java包的Python包装器)的全部内容,更多相关java使用python库_使用python中内容请搜索靠谱客的其他文章。
发表评论 取消回复