在Tomcat项目中从Java执行Python脚本 [英] Executing Python script from Java in Tomcat project

查看:1065
本文介绍了在Tomcat项目中从Java执行Python脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Java中执行Python脚本(包括Scipy和Numpy),该脚本应该由eclipse与tomcat项目捆绑在一起。从Java调用Python很简单:

  Runtime.getRuntime()。exec(python ...); 

如何实现将脚本捆绑在相应的路径上?这是可能的吗?

解决方案

我最近做了一些类似的事情,我可以从eclipse运行它。

我使用 jython plyjy



我将两个jar(jython.jar和plyjy.jar)保存在lib中Eclipse项目的文件夹,并将所需的python文件复制到项目的src文件夹中。



然后使用以下代码创建一个Python对象实例

  PySystemObjectFactory factory = new PySystemObjectFactory(InterfaceTye,moduleName,ClassName); 

在工厂对象的帮助下,我们可以创建指定模块的对象并调用该方法特定的模块。



我只能在eciplse中实现它,但我不知道如何捆绑相同的构建


I want to execute a Python script (including Scipy and Numpy) from Java which should be bundled with the tomcat project by eclipse. Calling Python from Java is trivial:

Runtime.getRuntime().exec("python ...");

How can I achieve bundling the script to call it at the corresponding path? Is this even possible?

解决方案

I did some thing similar recently , i am able to run it from eclipse.

I used jython and plyjy

i kept both the jars(jython.jar and plyjy.jar) in lib folder of the Eclipse project and copied the required python files to the src folder of the project.

Then created an Python Object Instance using the following code

PySystemObjectFactory factory = new PySystemObjectFactory(InterfaceTye, moduleName,ClassName);

with the help of factory object we can create an object of the specified module and call the methods of that particular module.

I was able to achieve it only in eciplse, but i am not sure how to bundle the same for the build

这篇关于在Tomcat项目中从Java执行Python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆