Using Jython with Maven

天涯浪子 提交于 2019-12-20 09:56:25

问题


I have a Maven module, that depends on various other Maven dependencies by which I am accessing through my jython code.

I am now done, and I would like to compile the project as a .jar, or even just run it without compiling, but I have no clue where to start.

Does anyone have any idea how I can run some .py files that accesses some Java libraries in other packages?

Also, how can I compile it as a .jar file when all is done and good?

Thanks!


回答1:


Compiling and integrating python

Use the jython-compile-maven-plugin. It allows you to deploy a standalone project that includes jython with libraries.

For demonstration of this plugin, see the demo project and its source code. It shows how to

  • launch a python console -- look at AbstractInitJython and InitJython on how to launch a python/jython console, how to execute python code snippets, and how to run a python script.

  • include python libraries -- the plugin also downloads and bundles python libraries (using easy_install) in the package phase, and adds them to the jar. The resulting jar can have all the libraries of the project, all pom dependencies and all the python libraries requested. The demo project shows this with the "nose" python library (see the pom file).

Testing python / jython code

The python-test-maven-plugin allows you to run your python tests alongside the normal junit tests. The demo project (look at the source at source code) shows the use of standard python unit tests (with nose) and BDD (behaviour testing) with the lettuce-clone freshen.


The sourceforge umbrella project is http://mavenjython.sourceforge.net/

Unlike maven-jython-plugin, they don't use the outdated jythonc compiler.




回答2:


I am now done, and I would like to compile the project as a .jar,

It looks like there is a maven-jython-plugin allowing to compile jython source files to Java class files.




回答3:


I've kinda figured out my answer to this. I shouldn't have tried to compile it, but instead wrap the python code with Java: http://jythonpodcast.hostjava.net/jythonbook/en/1.0/JythonAndJavaIntegration.html#using-jython-within-java-applications




回答4:


The compiler portion of jython, jythonc, is deprecated as of 2.5 -- http://wiki.python.org/jython/ReplaceJythonc -- a replacement is in the works.



来源:https://stackoverflow.com/questions/3660054/using-jython-with-maven

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!