distributor(Distributing Jython Apps in a Single JAR file)
Distributing Jython Apps in a Single JAR file
May 20, 2009 at 02:20 PM | categories:
python, java
| 12 Comments and 1 Reaction
Ive been writing a lot of one-off type applications at work lately, which is always kind of a joy for me because these sorts of applications dont need to be maintained or supported in any way, which means I can write them however I want.
So I write them in Python :)
Jython allows me to interface with all the plethora of Java libraries that we use at work, and it lets me program in a language that not only I can tolerate, but one that I respect and love.
But even though these are one-off applications, they still need to be easy to use, and in some cases I wont even be the one running the application. I want these applications to just work damnit.
So, packaging my Jython application into a single executable jar file that contains all of the third party dependancies inside is my goal. I want to send the user the jar file, have them double click on it, and have it immediately start running. It cant get a whole lot easier than that.
The Jython wiki has a page about doing something along these lines. The recipe there called the Jar Method works quite well. The one drawback that it has is that all of the Java dependancies need to be exploded into the main jar root, which when youre dealing with dozens of jar dependancies, it can start to get tedious, messy, and in some cases will even violate the license of a particular library.
One-Jar is a special class loader that can load a jar file that is inside of another jar file, something that the regular class loader from Sun is incapable of doing. Using One-Jar lets my application reside inside of a jar file and contain all my dependancies as seperate jar files inside the main jar file.
Ive created a sample project that shows how I normally create a new Jython project hosted inside a single jar file with One-Jar. Youll need the following tools to check out the project:
A Java SDK (tested with OpenJDK 1.6) Apache Ant (tested with version 1.7) Git (to checkout the project)Check out the project like so:
Build the project:
Run the example by double clicking it or via the command line:
This is just a demonstration app, it doesnt do a whole lot, it outputs an excel file in the current directory listing some computer parts. The point of the application is to show how Jython can integrate with existing Java third-party libraries (in this case Apache POI.)
Instructions for basing your own application on this example are contained inside the README.txt file.
创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!