|
[Jython-users] easy jython deployment on windows HOWTO
From: Carl Dr. Kleffner <cmkleffner@gm...> - 2004-10-14 16:44
|
This is what I do on windows machines:
For my work I created an easy to install Jython distro with
only three files:
- a windows cmd-file
- jython.jar
- jythonlib.zip
I don't use an external registry parameter file because I prefer
to set the options in the starter script instead.
No installation procedure is needed. The only condition is to
locate this 3 files in the same directory.
The command file looks like this:
>--------- jython.cmd -----------------------------<
@echo off
rem JYTHON_HOME: jython root directory
set JYTHON_HOME="%~dp0."
rem JYTHON_LIBPATH: location of jythonlib.zip
set JYTHON_LIBPATH="%~dp0jythonlib.zip\Lib"
rem JYTHON_PATH: location of jython.jar
set JYTHON_PATH="%~dp0jython.jar"
rem handle args (args may contain spaces)
set ARGS=
:loop
if [%1] == [] goto end
set ARGS=%ARGS% %1
shift
goto loop
:end
rem start a jython interpreter in JVM
java -Dpython.home=%JYTHON_HOME%
-Dpython.path=%JYTHON_LIBPATH%
-cp %JYTHON_PATH%;%CLASSPATH%
org.python.util.jython %ARGS%
>----------------------------------------------<
(Put the java command line in one single line
inside your jython.cmd file)
The pathname to jython.cmd is arbitrary. Spaces as well as special
characters in the pathname are allowed! One exception of this rule I
encountered is the use of the hash characters '#' in the pathname.
(I have no idea if this is a java or a jython problem)
The %~dp0 trick doesn't work on WIN9X, try out %0\.. or %0\..\
instead (I haven't tried it yet).
And don't forget to use the .bat extension on WIN9X!
How to build jythonlib.zip:
jythonlib.zip should contain the Lib\ directory of jython.
For performance reasons the Python modules should be precompiled.
You can precompile the modules in Lib with the
compileall.compile_dir function.
My jythonlib.zip looks like this:
Archive: jythonlib.zip
Length Date Time Name
-------- ---- ---- ----
6711 12-06-03 03:36 Lib/anydbm$py.class
2783 12-06-03 03:36 Lib/anydbm.py
5659 12-06-03 03:36 Lib/atexit$py.class
1327 12-06-03 03:36 Lib/atexit.py
8083 12-06-03 03:36 Lib/base64$py.class
2065 12-06-03 03:36 Lib/base64.py
..........
34466 12-06-03 03:36 Lib/zipfile$py.class
25147 12-06-03 03:36 Lib/zipfile.py
9735 12-06-03 03:36 Lib/zlib$py.class
3205 12-06-03 03:36 Lib/zlib.py
6984 12-06-03 03:36 Lib/__future__$py.class
3509 12-06-03 03:36 Lib/__future__.py
0 10-05-04 13:11 Lib/
-------- -------
5785342 460 files
I guess you can build it as a Java jar-file with Java's jar.exe,
but Winzip does the job for me.
Test your jython.cmd:
Jython 2.2a0 on java1.3.1_02 (JIT: null)
Type "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', 'C:\\tools\\jython\\.', 'C:\\tools\\jython\\jythonlib.zip\\Lib']
Here is an example for jython skripts that uses the xerces parser and
th IBM swt toolkit. Of course you can set CLASSPATH in your global
environment, but it may be more convinient for you to set the
CLASSPATH for the needed Java libs in your starter script.
AND you have to set the '-Djava.library.path' option to tell Java
where to find the Windows swt.dll:
In this example the files:
xercesImpl.jar, xml-apis.jar, swt.jar and swt-win32-2133.dll
are located in jython's root directory.
(You may need the full pathnames of your environment)
>--------- jython.cmd -----------------------------<
@echo off
rem JYTHON_HOME: directory where jython lives
set JYTHON_HOME="%~dp0."
rem JYTHON_LIBPATH: location of jythonlib.zip
set JYTHON_LIBPATH="%~dp0jythonlib.zip\Lib"
rem JYTHON_PATH: location of jython.jar
set JYTHON_PATH="%~dp0jython.jar"
rem JYTHON_XERXES: xerces parser: xercesImpl.jar, xml-apis.jar
set JYTHON_XERXES="%~dp0xercesImpl.jar;%~dp0xml-apis.jar"
rem JYTHON_SWT: IBM eclipse swt.jar
set JYTHON_SWT="%~dp0swt.jar"
rem JYTHON_JAVA_PATH: location of additional dlls: swt-win32-2133.dll
set JYTHON_JAVA_PATH=%JYTHON_HOME%
rem handle args (args may contain spaces)
set ARGS=
:loop
if [%1] == [] goto end
set ARGS=%ARGS% %1
shift
goto loop
:end
rem start a jython interpreter in JVM
java -Djava.library.path=%JYTHON_JAVA_PATH%
-Dpython.home=%JYTHON_HOME%
-Dpython.path=%JYTHON_LIBPATH%
-cp %JYTHON_PATH%;%JYTHON_XERXES%;%JYTHON_SWT%;%CLASSPATH%
org.python.util.jython %ARGS%
>----------------------------------------------<
(Put the java command line in one single line
inside your jython.cmd file)
If you don't want to use zipped Python modules use:
set JYTHON_LIBPATH="%~dp0Lib"
instead.
None of this is really new, but I never found a survey
for setting up a convenient jython distro.
Regards
Carl
--
GMX ProMail mit bestem Virenschutz http://www.gmx.net/de/go/mail
+++ Empfehlung der Redaktion +++ Internet Professionell 10/04 +++
|
| Thread | Author | Date |
|---|---|---|
| [Jython-users] easy jython deployment on windows HOWTO | Carl Dr. Kleffner <cmkleffner@gm...> |