从Eclipse包装和部署Jython程序 [英] Packaging and deploying a Jython program from Eclipse

查看:136
本文介绍了从Eclipse包装和部署Jython程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我一直在编写一些Jython代码。我一直在使用最新版本的Eclipse IDE与PyDev插件进行开发。到目前为止,事情已经适度地容忍了。我已经完成了所有的Python脚本,我成功地将一些JAR文件和另一个Java项目的类目录作为外部依赖关系。一切似乎都可以通过Eclipse IDE运行。



现在我需要打包所有东西并进行部署。从我可以收集的东西,最好的方式是将所有内容打包在一个JAR文件中。 Jython文档建议从jython.jar文件开始,并添加它。好。所以我修改我的主要python模块,并开始将所有的python源添加到JAR。



它执行,但当然找不到所有的外部依赖。 >

如何添加外部JAR文件,以便Jython解释器正确看到它?如何在一个这样的设置中管理更复杂的依赖关系?



是否有一个Eclipse插件,或者像Ant或Maven这样可以处理所有这些步骤的东西对我而言,按下一个按钮?



我不能第一个需要部署具有复杂依赖关系的Jython代码的人吗?

解决方案

我已经取得了一切进展,所以我想我会把一些笔记在这里,以防万一他们帮助别人。我仍然希望听到他人的经验,试图把这样的东西放在一起。



事实证明,截至3.5的Eclipse具有Java的项目导出选项 - > Runnable JAR文件。如果使用此选项,则可以在导出向导中指向Java主类。您还可以选择重新打包所有依赖于您的新JAR文件的JAR。确保选中该框以将导出保存为ANT构建,以便您可以快速重复此过程。请注意,首次通过界面执行此操作时,可能会失败,但仍会创建一个JAR文件。



现在这里是奇怪的地方。为了跟踪所有的依赖关系,我仍然在我的项目中使用一个大部分不完整的Maven构建。我创建Maven .POM文件。我告诉Maven我的外部JAR依赖关系是什么。然后我告诉Maven为我做一个依赖更新。它将所有内容都按预期的方式拉入我的Maven存储库。



现在,当我做ANT构建时,看起来它的JAR列表将包含在最终版本中Maven的。我不确定是否应该这样工作。我也不是100%肯定它是正常工作。我想我会找出什么时候我必须向该项目添加另一个外部JAR。



无论如何,如果你遵循这个运行脚本。



接下来,建立另一个您的Jython目录中的Jython JAR文件的副本。这个应该有/ Lib目录被拉入JAR。保存它,然后将您的Eclipse IDE Jave Build选项指定为该JAR上的PyDev项目作为外部依赖关系。您的JarRunner现在将在Jython下工作并执行运行 .py文件。



如果所有这些都有效,您应该可以重新运行ANT从较早版本导出的构建,最终将使用单个JAR文件,您可以在命令行中执行以下命令:



java -jar {yourjar} args



并分发给您的客户,不需要额外的依赖。



如果这一切似乎有点复杂,那就是。如果有人有更好的方法来设置这个全部使用Eclipse,请让我知道。


So I've been pigeon-holed into writing some Jython code. I've been using the latest version of Eclipse IDE with the PyDev plugin for development. Up until now, things have been moderately tolerable. I've gotten all my Python scripts working and I'm successfully including a couple of JAR files and the class directory of another Java project as external dependencies. Everything seems to run fine through the Eclipse IDE.

Now I need to package everything up and deploy it. From what I can gather, the best way to do this would be to package everything up in a JAR file. The Jython documentation suggests starting out with the jython.jar file and adding to it. OK. So I modify my main python module and start adding all my python source to the JAR.

It executes but of course can't find all the external dependencies.

How is one supposed to add the external JAR files so that they are correctly seen by the Jython interpreter? How is one supposed to manage more complex dependencies in a setup like this?

Is there a plugin for Eclipse or maybe something like Ant or Maven that can handle all of these steps for me with the push of a button?

I can't be the first person that has needed to deploy Jython code with complex dependencies can I?

解决方案

I've made some headway on getting this all working so I thought I would put some notes here in case they help anyone else out. I'd still like to hear from others on their experiences trying to put together something like this.

It turns out that Eclipse as of 3.5 has a project export option for Java -> Runnable JAR File. If you use this option, you can point to a Java main class in the export wizard. You also have the option to have it repackage all the JARs that you are dependent on in your new JAR file. Make sure to check the box to save the export as an ANT build so that you can repeat the process quickly. NOTE that the first time you do this through the interface, it may fail, but it will still have created a JAR file.

Now here's where it gets strange. To track all the dependencies, I am still using a mostly incomplete Maven build in my project. I create the Maven .POM file. And I told Maven what my external JAR dependency was. I then told Maven to do a dependency update for me. It pulled everything into my Maven repository as expected.

Now when I do my ANT build, it appears that it is getting its list of JARs to include in the final build from Maven. I'm not really sure if it is supposed to work that way. I'm also not 100% sure that it is working. I guess I'll find out when I have to add another external JAR to the project.

Anyways, if you follow this question you'll see that you can take the latest builds of Jython and pull the org.python.util.JarRunner.java file out and use it in your own project. This is you Java.main class that you will need to point your ANT build at. From there, convert your main Python/Jython script to be the run script that was talked about in that question.

Next, build up another copy of the Jython JAR file in your Jython directory. This one should have the /Lib directory pulled into the JAR. Save that off and then point your Eclipse IDE Jave Build option for your PyDev project at that JAR as an external dependency. Your JarRunner will now work and execute the run.py file under Jython.

If all that works, you should then be able to rerun the ANT exported build from earlier and you will end up with a single JAR file that you can execute on the command line as:

java -jar {yourjar} args

And distribute to your customers without any additional dependencies.

If that all seems a little bit convoluted, it is. If anyone has a better way of setting this all up using Eclipse, please let me know.

这篇关于从Eclipse包装和部署Jython程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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