Connor, Adam J | 14 Jan 16:18 2011
Picon

Using Jython to compile a script and run it from a jar

(Some of the stacktrace elided to avoid the need for moderation on message length.)

 

Hi, fellow Jython users. I’m hoping that someone with a better understanding of Jython internals than I can help me out.

 

This question is related to the article “Distributing Jython Scripts” at http://wiki.python.org/jython/JythonFaq/DistributingJythonScripts

 

What I’m trying to do: execute some Django functionality from django.template, and, I hope, package it all up in a jar so that we can use it from an existing Java program. (Why Django instead of something else? Because we use Django for Python, and this is related to making an older, legacy product more compatible.)

 

The test.py script below is a simplified version that triggers the bug I’m hitting.

 

What I’ve done:

1.      copied jython.jar to “jythonall.jar”

2.      copied the various Python packages in Lib/ into the jar – in particular, django.

3.      compiled my test script using jython –m py_compile test.py (results in test$py.class)

4.      Added test$py.class to the jar.

 

Test Results:

test.py:

import django.template

print 'done'

If I run the command java –cp .\jythonall.jar org.python.util.jython test.py, it works as expected and prints “done”.

 

But if I run the command java –cp .\jythonall.jar test$py, I get the following stacktrace. My question is: Why? What do I need to do for it to work?

 

Stacktrace:

Documents\jython_templates\jythonall.jar'

Exception in thread "main" Traceback (most recent call last):

  File "test2$py", line 1, in <module>

  File "__pyclasspath__/django/template/__init__$py.class", line 53, in <module>

 

  File "__pyclasspath__/inspect.py", line 31, in <module>

  File "__pyclasspath__/string$py.class", line 122, in <module>

  File "__pyclasspath__/string$py.class", line 115, in __init__

  File "__pyclasspath__/re$py.class", line 214, in escape java.lang.NullPointerException

        at org.python.core.PyObject._add(PyObject.java:1994)

        at re$py.escape$11(C:\jython2.5.2rc3\Lib\re.py:215)

        at re$py.call_function(C:\jython2.5.2rc3\Lib\re.py)

        at org.python.core.PyTableCode.call(PyTableCode.java:165)

... (elided)

        at org.python.core.PyTableCode.call(PyTableCode.java:165)

        at org.python.core.PyCode.call(PyCode.java:18)

        at org.python.core.imp.createFromCode(imp.java:386)

        at org.python.core.imp.createFromCode(imp.java:357)

        at org.python.core.Py.runMain(Py.java:950)

        at test2$py.main(C:\Documents and Settings\adamc\My Documents\jython_templates\test2.py)

 

java.lang.NullPointerException: java.lang.NullPointerException

 

BTW, other Django imports work, so I suspect it might be something particular to django.template’s __init__.py.

 

Thanks in advance for any help!

 

adam connor / Financial Information Systems, The University of Texas at Austin

------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users
Pierre Thibault | 14 Jan 16:52 2011
Picon

Re: Using Jython to compile a script and run it from a jar

Hello Connor,

If using " java –cp .\jythonall.jar org.python.util.jython test.py" works, what is the problem? It is the way to run Jython script with "java" (http://wiki.python.org/jython/JythonFaq/DistributingJythonScripts). The org.python.util.jython class is containing the initialization code needed for Jython. If it does not run, bad thing can happen.

2011/1/14 Connor, Adam J <adam.connor <at> austin.utexas.edu>

(Some of the stacktrace elided to avoid the need for moderation on message length.)

 

Hi, fellow Jython users. I’m hoping that someone with a better understanding of Jython internals than I can help me out.

 

This question is related to the article “Distributing Jython Scripts” at http://wiki.python.org/jython/JythonFaq/DistributingJythonScripts

 

What I’m trying to do: execute some Django functionality from django.template, and, I hope, package it all up in a jar so that we can use it from an existing Java program. (Why Django instead of something else? Because we use Django for Python, and this is related to making an older, legacy product more compatible.)

 

The test.py script below is a simplified version that triggers the bug I’m hitting.

 

What I’ve done:

1.      copied jython.jar to “jythonall.jar”

2.      copied the various Python packages in Lib/ into the jar – in particular, django.

3.      compiled my test script using jython –m py_compile test.py (results in test$py.class)

4.      Added test$py.class to the jar.

 

Test Results:

test.py:

import django.template

print 'done'

If I run the command java –cp .\jythonall.jar org.python.util.jython test.py, it works as expected and prints “done”.

 

But if I run the command java –cp .\jythonall.jar test$py, I get the following stacktrace. My question is: Why? What do I need to do for it to work?

 

Stacktrace:

Documents\jython_templates\jythonall.jar'

Exception in thread "main" Traceback (most recent call last):

  File "test2$py", line 1, in <module>

  File "__pyclasspath__/django/template/__init__$py.class", line 53, in <module>

 

  File "__pyclasspath__/inspect.py", line 31, in <module>

  File "__pyclasspath__/string$py.class", line 122, in <module>

  File "__pyclasspath__/string$py.class", line 115, in __init__

  File "__pyclasspath__/re$py.class", line 214, in escape java.lang.NullPointerException

        at org.python.core.PyObject._add(PyObject.java:1994)

        at re$py.escape$11(C:\jython2.5.2rc3\Lib\re.py:215)

        at re$py.call_function(C:\jython2.5.2rc3\Lib\re.py)

        at org.python.core.PyTableCode.call(PyTableCode.java:165)

... (elided)

        at org.python.core.PyTableCode.call(PyTableCode.java:165)

        at org.python.core.PyCode.call(PyCode.java:18)

        at org.python.core.imp.createFromCode(imp.java:386)

        at org.python.core.imp.createFromCode(imp.java:357)

        at org.python.core.Py.runMain(Py.java:950)

        at test2$py.main(C:\Documents and Settings\adamc\My Documents\jython_templates\test2.py)

 

java.lang.NullPointerException: java.lang.NullPointerException

 

BTW, other Django imports work, so I suspect it might be something particular to django.template’s __init__.py.

 

Thanks in advance for any help!

 

adam connor / Financial Information Systems, The University of Texas at Austin


------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand
malware threats, the impact they can have on your business, and how you
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users




--


A+

-------------
Pierre
My blog (http://pierrethibault.posterous.com)
YouTube page (http://www.youtube.com/user/tubetib)
Twitter (http://twitter.com/pierreth2)
Google profile (http://www.google.com/profiles/106045618354056753098)

------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users

Gmane