Picon

Re: Jython in Eclipse

I got it too, may be the configuration of execution must be changed
Kevin Baggett escribió:
> Hi,
> I have been trying to use Jython within Eclipse, running a very simple 
> script that just prints something.
> Every time I try to run, it comes up with
> An internal error occurred during: "Launching"
> No details, nothing on the console that I opened up Eclipse with.
> Any ideas?
> Thanks!
> Kevin Baggett, UW-SSEC
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems?  Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >>  http://get.splunk.com/
> _______________________________________________
> Jython-users mailing list
> Jython-users <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jython-users
>   

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
Updike, Clark | 1 Aug 02:59
Favicon

Re: referring to the Java Object[] type in Jython


from types import ArrayType

Then use it where you were using arrayType.

-Clark

> I wrote the following code for converting a Jython list-of-lists to a
> Java Object[][].  To get the Object[] type I construct an instance,
> then ask it what its type is -- is there a less roundabout way?
> 
> from java.lang import Object
> import jarray
> 
> listOfLists = [ [1, 2, 3], [2, 3, 4], [3, 4, 5] ]
> 
> arrayType = jarray.array([], Object).__class__
> listOfArrays = map(lambda x:  jarray.array(x, Object), listOfLists)
> arrayOfArrays = jarray.array(listOfArrays, arrayType)
> 
> Thanks,
> -David

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
werckmeister1 | 1 Aug 16:19
Picon
Picon

How to run a .py file from Jython

Dear all,

I am not sure if the following is a trivial problem or not; thanks a lot for pointers in the right direction:

I want to write a package in Jython, containing some helper classes and functions (class_foo.py
class__1_foo.py ...) and finally a program program_foo.py importing and using the aforementioned classes.

I want to start program_foo.py from another jython program, say main.py. 
- How can I run the file program_foo.py from main.py?
- Will program_foo.py then find the import files in the same package or do I have to set additional
environment variables?

Maybe slightly off-topic: It would possibly also help if I could run a start.bat from jython. Is there a way
to do that?

Thanks a lot for your support.

Kind regards

Markus
--

-- 
GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
(Continue reading)

Utkarsh Upadhyay | 1 Aug 16:40
Picon
Gravatar

Re: How to run a .py file from Jython



On 8/1/07, werckmeister1 <at> gmx.de <werckmeister1 <at> gmx.de> wrote:
Dear all,

I am not sure if the following is a trivial problem or not; thanks a lot for pointers in the right direction:

I want to write a package in Jython, containing some helper classes and functions (class_foo.py class__1_foo.py ...) and finally a program program_foo.py importing and using the aforementioned classes.

I want to start program_foo.py from another jython program, say main.py.
- How can I run the file program_foo.py from main.py?

import program_foo.py

should be able to do it.

- Will program_foo.py then find the import files in the same package or do I have to set additional environment variables?

Should work out of the box. Though you may need to use hierarchy just as in Java, like org/cache/ ... will convert to org.cache. ... ,e etc.

Maybe slightly off-topic: It would possibly also help if I could run a start.bat from jython. Is there a way to do that?

import os
os.system("start.bat")
 
Should do.

HTH,
musically_ut.


Thanks a lot for your support.

Kind regards

Markus
--
GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users



--
Never trust a spiritual leader who cannot dance. ~Mr. Miyagi, The Next Karate Kid
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users
werckmeister1 | 1 Aug 17:02
Picon
Picon

Re: How to run a .py file from Jython

Thank you for your reply. 
Sorry, I must give some more background information. Let's say main.py is a basic editor; I edit
program_foo.py in main.py and want to start it from main after editing. If I repeat the import statment
after editing; will the edited version be reimported and executed?

> 
> 
> import program_foo.py
> 
> should be able to do it.
> 

Thanks again

Markus
--

-- 
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! 
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
David Handy | 1 Aug 17:15
Picon
Favicon

Re: How to run a .py file from Jython

If you repeat the command:

import program_foo

nothing will happen. You have to do this:

reload(program_foo)

to re-import a module whose source file has changed. But this won't re-load any other module that
program_foo.py imported, so if those files changed you still have a problem.

Maybe your other idea of running a start.bat file from main.py is a better idea.

David H 

-----Original Message-----
From: jython-users-bounces <at> lists.sourceforge.net
[mailto:jython-users-bounces <at> lists.sourceforge.net] On Behalf Of werckmeister1 <at> gmx.de
Sent: Wednesday, August 01, 2007 11:03 AM
To: Utkarsh Upadhyay
Cc: jython-users <at> lists.sourceforge.net
Subject: Re: [Jython-users] How to run a .py file from Jython

Thank you for your reply. 
Sorry, I must give some more background information. Let's say main.py is a basic editor; I edit
program_foo.py in main.py and want to start it from main after editing. If I repeat the import statment
after editing; will the edited version be reimported and executed?

> 
> 
> import program_foo.py
> 
> should be able to do it.
> 

Thanks again

Markus
--
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! 
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/ _______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
Moore, Greg | 1 Aug 21:08
Picon
Favicon

Re: How do I make this easily usable by others? possible bug?

Hello Again,

I just wanted to let you know I was successful, thanks to all your help
(Charlie and Odi). I was able to put all the java classes I needed under
\org and the *.py under \lib and it all worked wonderfully. I now have a
jumbo all in one jar file that works great! Odi I'd like you permission
to use some of the info on your web page to create a wiki entry that
documents what I did so it might help others.

However, I did notice something odd when I was trying the classpath
method.
This gets a little lengthy sorry about that.

I get different results when typing in commands into the interpreter
then I do when I specify a script on the commandline. This only seems to
happen with the standalone jar I did not see this with the
non-standalone installation. Let me explain a little further:

On Windows XP sp2 with the following Environment:

PATH="c:\Program Files\Java\jre1.5.0_11\bin"
CLASSPATH=c:\dist\lib\commons-codec-1.3.jar;c:\dist\lib\commons-logging-
1.0.4.jar;c:\dist\lib\commons-httpclient-3.1-rc1.jar;c:\dist\lib\dom4j-1
.6.1.jar;c:\dist\lib\jaxen-1.1.1.jar;c:\dist\lib\log4j-.2.8.jar;"c:\Prog
ram Files\Java\jre1.5.0_11\lib\rt.jar"

This is what I saw:
C:\jython2.2>java -cp %classpath%;.\jythonStandalone.jar
org.python.util.jython

Jython 2.2rc2 on java1.5.0_11
Type "copyright", "credits" or "license" for more information.
>>> from javax import swing
Traceback (innermost last):
  File "<console>", line 1, in ?
ImportError: cannot import name swing
>>> from javax import *
Traceback (innermost last):
  File "<console>", line 1, in ?
ImportError: no module named javax
>>> ^Z

However everything works fine if I use, for example, the Jython Console
from http://code.google.com/p/jythonconsole/ using a similar command to
the one above: C:\jython2.2>java -cp %classpath%;.\jythonStandalone.jar
org.python.util.jython c:\Libs\jythonconsole-0.0.4\console.py 

At the top of console.py there are a bunch of swing imports.
Just for the purposes of completeness, If I type in a line like "from
java import *" or "from java.lang import String" everything works fine
and there are no import errors.

Here are some other tests I ran if your interested

C:\jython2.2>java -cp %classpath%;.\jythonStandalone.jar
org.python.util.jython
Jython 2.2rc2 on java1.5.0_11
Type "copyright", "credits" or "license" for more information.
>>> from org.dom4j import *
Traceback (innermost last):
  File "<console>", line 1, in ?
ImportError: no module named dom4j
>>> from org.apache.commons.httpclient import *
Traceback (innermost last):
  File "<console>", line 1, in ?
ImportError: no module named apache
>>> from org.apache.commons import *
Traceback (innermost last):
  File "<console>", line 1, in ?
ImportError: no module named apache
>>> import org
>>> dir
<built-in function dir>
>>> dir(org)
['__name__', 'python']
>>> ^Z

Now Using the SAME environment settings but the NON standalone jar every
thing seems to work just fine. As shown below.

C:\jython2.2>java -cp %classpath%;.\jython.jar org.python.util.jython
*sys-package-mgr*: processing new jar,
'C:\dist\lib\commons-codec-1.3.jar'
*sys-package-mgr*: processing new jar,
'C:\dist\lib\commons-logging-1.0.4.jar'
*sys-package-mgr*: processing new jar,
'C:\dist\lib\commons-httpclient-3.1-rc1.jar'
*sys-package-mgr*: processing new jar, 'C:\dist\lib\dom4j-1.6.1.jar'
*sys-package-mgr*: processing new jar, 'C:\dist\lib\jaxen-1.1.1.jar'
*sys-package-mgr*: processing new jar, 'C:\dist\lib\log4j-1.2.8.jar'
*sys-package-mgr*: processing new jar, 'C:\Program
Files\Java\jre1.5.0_11\lib\rt.jar'
*sys-package-mgr*: processing new jar, 'C:\Program
Files\Java\jre1.5.0_11\lib\jsse.jar'
*sys-package-mgr*: processing new jar, 'C:\Program
Files\Java\jre1.5.0_11\lib\jce.jar'
*sys-package-mgr*: processing new jar, 'C:\Program
Files\Java\jre1.5.0_11\lib\ext\dnsns.jar'
*sys-package-mgr*: processing new jar, 'C:\Program
Files\Java\jre1.5.0_11\lib\ext\sunjce_provider.jar'
*sys-package-mgr*: processing new jar, 'C:\Program
Files\Java\jre1.5.0_11\lib\ext\sunpkcs11.jar'
Jython 2.2rc2 on java1.5.0_11
Type "copyright", "credits" or "license" for more information.
>>> from javax import *
>>>

Sorry this got a little longwinded. But I don't know a more concise way
of documenting it.

So I guess the question is... Bug or feature? I couldn't test this with
2.1 because this appears to be specific to the standalone jar and it was
unavailable with the 2.1 release.

Regards,
Greg.

This message and any attachments are intended only for the use of the addressee and may contain information
that is privileged and confidential. If the reader of the message is not the intended recipient or an
authorized representative of the intended recipient, you are hereby notified that any dissemination of
this communication is strictly prohibited. If you have received this communication in error, please
notify us immediately by e-mail and delete the message and any attachments from your system.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
David Huebel | 1 Aug 22:45
Picon

Re: Jython in Eclipse

On 7/31/07, Kevin Baggett <kevinb <at> ssec.wisc.edu> wrote:
> Hi,
> I have been trying to use Jython within Eclipse, running a very simple
> script that just prints something.
> Every time I try to run, it comes up with
> An internal error occurred during: "Launching"
> No details, nothing on the console that I opened up Eclipse with.
> Any ideas?
> Thanks!
> Kevin Baggett, UW-SSEC

If you're trying to use a launch configuration created by a
Python/Jython development plugin for Eclipse, I would suggest creating
your own launch configuration based on the "Java Application"
launcher.  I tried a couple such plugins that generated broken launch
configurations by default.

-David

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
David Huebel | 1 Aug 22:59
Picon

Re: How do I make this easily usable by others? possible bug?

On 8/1/07, Moore, Greg <Greg_W_Moore <at> adp.com> wrote:
> >>> from javax import swing
> Traceback (innermost last):
>   File "<console>", line 1, in ?
> ImportError: cannot import name swing
> >>> from javax import *
> Traceback (innermost last):
>   File "<console>", line 1, in ?
> ImportError: no module named javax

Try:

> import sys
> sys.add_package('javax.swing')
> from javax.swing import JFrame

If this works, then the problem is that the javax.swing package is
available on the classpath, but Jython did not find it in its initial
package scan.  See:

http://wiki.python.org/jython/PackageScanning

If Jython didn't find a Java package in its initial package scan, then
it assumes it doesn't exist until you tell it otherwise by calling
sys.add_package().  I don't know if import * works for packages that
weren't scanned.

If sys.add_package() doesn't help, then javax.swing.JFrame isn't
available to the class loader, in which case it's probably a classpath
or class loader issue.

-David

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
David Huebel | 2 Aug 01:00
Picon

Re: referring to the Java Object[] type in Jython

On 7/31/07, Updike, Clark <Clark.Updike <at> jhuapl.edu> wrote:
>
> from types import ArrayType
>
> Then use it where you were using arrayType.

This is indeed equivalent to my code.  Unfortunately, upon finally
running my code to completion, I found out that it didn't work.
PyArray instances wrap Java arrays, and when instances of PyArray are
passed to methods that expect Java arrays, a reference to the wrapped
array is passed.  The unwrapping isn't recursive, so arrays of arrays
cannot be constructed in Jython and passed to Java.

One solution, tested and working here, is to implement a factory in
Java to create arrays of arrays.  Jython code can set members of the
Java array-of-arrays to arrays created using jarray.  Then the
array-of-arrays can be passed back to Java code.  So:

arrayOfArrays = FactoryImplementedInJava.createArrayOfArrayOfObjects(2)
arrayOfArrays[0] = jarray.zeros(10, Object)
arrayOfArrays[1] = jarray.zeros(10, Object)
javaObject.methodTakingArrayOfArrayOfObjects(arrayOfArrays) # works!

-David

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/

Gmane