Differences between revisions 1 and 2
Revision 1 as of 2007-08-10 19:07:29
Size: 5135
Editor: GregMoore
Comment:
Revision 2 as of 2007-08-10 19:21:04
Size: 5097
Editor: GregMoore
Comment:
Deletions are marked like this. Additions are marked like this.
Line 19: Line 19:
Line 32: Line 33:
Optionally you can add a script as a parameter which would, as usual, be run. Optionally you can add a script as a parameter which would run as usual.
Line 40: Line 41:
(Linux / Unix) java -cp /path/to/jython2.2/jython.jar:$CLASSPATH org.python.util.jython [file.py]
(windows) java -cp "c:\jython2.2\jython.jar;%CLASSPATH%" org.python.util.jython [file.py]
 *(Linux / Unix) java -cp /path/to/jython2.2/jython.jar:$CLASSPATH org.python.util.jython [file.py]
 *(windows) java -cp "c:\jython2.2\jython.jar;%CLASSPATH%" org.python.util.jython [file.py]
Line 70: Line 71:
    total commander: http://www.ghisler.com/index.htm
    servant salamander: http://www.altap.cz/download.html#sal25
    I've tried using winzip but had difficulty with it.
    * total commander: http://www.ghisler.com/index.htm
    * servant salamander: http://www.altap.cz/download.html#sal25
Line 74: Line 74:
Obviously the tools listed are just examples and you should use what ever works best for you.
Maybe ant would work. if someone wants to post an ant script that would be wonderful because
I'm hardly an ant expert.
Obviously the tools listed are just examples, not endorsements(!). You should use what ever works best for you. I've tried using winzip but had difficulty with it. Maybe ant would be another way to do this. if someone wants to post an ant script that would be wonderful because I'm hardly an ant expert.
Line 78: Line 76:
for additional I would strongly suggest you review Odi's notes at http://jython.extreme.st/talk/talk.html for additional info I would strongly suggest you review Oti's notes at http://jython.extreme.st/talk/talk.html
Line 81: Line 79:
for me personally I found the jar method workd best for me. I had the supporting
jars and scripts in the standalone jython and then the primary script seperatly.
So I had 2 files that I distributed one .jar and one .py. Because the support files
were pretty stable and didn't change this allowed me to easily improve and fix
bugs in the main .py file
for me personally I found the jar method worked best for me. I had the supporting jars and scripts in the standalone jython jar and then the primary script separately. So I had 2 files that I distributed one .jar and one .py. Because the support files were pretty stable and didn't change this allowed me to easily improve and fix bugs in the main .py file
Line 87: Line 81:
I could have only distributed a single jar file by renaming my main .py file
to __run__.py and putting it into the /lib directory of the jar file. Then the command simply becomes
java -jar jython.jar

The main python file should be called __run__.py
then bundle into a jar file and use:

jython -jar mypthonfiles.jar

Finally, as in all things YMMV.
If you have different experences or just think I'm just crazy then
dont just sit there and complain, contribute to the
wiki!
I could have only distributed a single jar file by renaming my main .py file to __run__.py and putting it into the /lib directory of the jar file. Then the command simply becomes java -jar jython.jar (or whatever I want to call the jar file.
Line 104: Line 88:
Finally, as in all things YMMV. If you have different experences or just think I'm just crazy then
dont just sit there and complain, contribute to the wiki!

Distributing Jython Scripts

JythonFaq

TableOfContents


How can do others use scripts/applications I've developed?

Initial creation date: Aug 2007

There are several ways to accomplish this but text will only cover distributing code you've written so others with out a Jython installation can use them. If someone wants to cover deployment to a web app server or embedded deployment, please do! These are beyond the scope of this text and more importantly my personal knowledge.

There are really 2 main ways to accomplish distributing your code and like most things Jython, its pretty easy.

Requirements

For your script to run on another PC there isn't much in the way of requirements really only 2 that I can think of.

  • You need reasonably current JVM installed on the target machine, I've used every thing from Java 1.4.2 through Java 1.6
  • You need the standalone Jython Jar.

What I did is install Jython twice. Once as a regular installation (not standalone) and then once as standalone. then I renamed the standalone jyhton jar file to jythonStandalone.jar, moved it into my original Jython2.2 directory and deleted the other one.

Using the Class Path.

Just set up the classpath with all the jars needed and passes that to java with -cp. That's a pretty standard thing for command line Java tools to do, it isn't specific to Jython. If you're going to do that, you can't use -jar though. Just add the jython jar to the things you've added to the classpath and give Jython's main class, org.python.util.jython, explicitly. Optionally you can add a script as a parameter which would run as usual.

So this would boil down to

  • having your scripts (*.py) outside the standalone jython.jar
  • having all the .jars you need on the classpath (including standalone jython.jar)
  • start java with the appropriate -cp (-classpath) option using a command.

for example:

  • (Linux / Unix) java -cp /path/to/jython2.2/jython.jar:$CLASSPATH org.python.util.jython [file.py]
  • (windows) java -cp "c:\jython2.2\jython.jar;%CLASSPATH%" org.python.util.jython [file.py]

Using the Jar Method

This is my favorite method of distribution. Its less hassle for you, the developer, with fewer files to keep track of and easier for your end users to use.

If you are not using any 3rd party jar files the very simplest way is to add them to the standalone jython.jar, in the /Lib folder

if you ARE using 3rd party jars such as dom4j or maybe Apache Commons jars; what worked very well for me is to explode the jar files, delete the meta_inf directory since you wont need it and copy the the org or com directory into the standalone Jython jar file into the /org directory. If you do that, you don't have to mess with python.path and the like. Imports should just work.

So this would boil down to

  • having your scripts (*.py) inside standalone jython.jar in the /lib directory
  • having all the classes (*.class) in the /org or /com directory
  • having all the .jars you need on the classpath (including standalone jython.jar)
  • start java with the -jar option.

for example: java -jar jython.jar {optional .py file}

you can manipulate .jar files with a tools like:

Obviously the tools listed are just examples, not endorsements(!). You should use what ever works best for you. I've tried using winzip but had difficulty with it. Maybe ant would be another way to do this. if someone wants to post an ant script that would be wonderful because I'm hardly an ant expert.

for additional info I would strongly suggest you review Oti's notes at http://jython.extreme.st/talk/talk.html (search for Script Deployment)

for me personally I found the jar method worked best for me. I had the supporting jars and scripts in the standalone jython jar and then the primary script separately. So I had 2 files that I distributed one .jar and one .py. Because the support files were pretty stable and didn't change this allowed me to easily improve and fix bugs in the main .py file

I could have only distributed a single jar file by renaming my main .py file to run.py and putting it into the /lib directory of the jar file. Then the command simply becomes java -jar jython.jar (or whatever I want to call the jar file.

Ok maybe one mention of webstart: check out these postings to the mailing list (all from aug 2007):

Finally, as in all things YMMV. If you have different experences or just think I'm just crazy then dont just sit there and complain, contribute to the wiki!

I'd like to thank Oti H., Charlie G., Frank W., and all the others that have helped along the way.

JythonFaq/DistributingJythonScripts (last edited 2014-06-13 19:07:57 by AdamBurke)