David Griffiths | 4 Nov 10:28
Picon
Gravatar

Dependency on Java 5 or above?

Hi, I just tried to install 2.5 beta on a machine with Java 142 and
got the following message:

The java class could not be loaded.
java.lang.UnsupportedClassVersionError:
org/python/util/install/Installation (Unsupported major.minor version
49.0)

Does Jython now depend on Java 5 or above? (There are plenty of people
out there still using 142 but of course they may not be the most
likely candidates to want to play with Jython :)

Cheers,

Dave

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
Oti | 4 Nov 10:36
Picon
Gravatar

Re: Dependency on Java 5 or above?

Hi Dave,


yes, the 2.5 alphas and betas require java 1.5 or higher.
If there is a need for using java 1.4.2, we can only offer the stable version, Jython 2.2.1

best wishes,
Oti.


On Tue, Nov 4, 2008 at 10:28 AM, David Griffiths <david.griffiths <at> gmail.com> wrote:
Hi, I just tried to install 2.5 beta on a machine with Java 142 and
got the following message:

The java class could not be loaded.
java.lang.UnsupportedClassVersionError:
org/python/util/install/Installation (Unsupported major.minor version
49.0)

Does Jython now depend on Java 5 or above? (There are plenty of people
out there still using 142 but of course they may not be the most
likely candidates to want to play with Jython :)

Cheers,

Dave

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
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 the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users
dudeja.rajat | 4 Nov 14:56
Picon

Hello to everyone. And my first basic question - How to use a Java class in Jython?

Hi Folks,

This is my first post to the users mailing list. Hello to every one there.
I'm a Jython newbie and I only know Python. I hope to learn many new things from you and try to answer the questions as far as possible asked on this list.

So here I'm with my basic question:

How can use a Java class in Jython?

NB - Java is completely an alien language to me.

Cheers,
Rajat

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users
claudef | 4 Nov 15:39
Picon
Gravatar

Re: Hello to everyone. And my first basic question - How to use a Java class in Jython?


Dear Rajat,

The easieat way to use a Java class is through the Jython interpreter. Below a sample code that illustrate some of the concepts.

Step 1 - Import the class pointing to the java package name. To avoid eventual name conflicts, rename a Java  class name during the import. A sample:  
          from java.util import Calendar as JavaCalendar
         from java.text import SimpleDateFormat
 
Step 2 - Use the Java class right from the shelf (no instance creation is required, no "new")
              mytoday = JavaCalendar.getInstance()  
        sdf = SimpleDateFormat("MM/dd/yyyy")
       
Step 3 - Use the Java class methods the same way as you use to do under Python                  
       timev = JavaCalendar.getTime(mytoday)
       stringdate = sdf.format(timev)
       print ("The new age of Java & Python starts at date = " +stringdate)

C:\Jython\myprojects\testing>jython classtest1.py
The new age of Java & Python starts at date = 11/04/2008  

Have fun with Java classes and Jython.

Regards,
Claude


Claude Falbriard
Developer
AMS Hortolândia / SP - Brazil
phone: +55 13 9762 4094
cell:       +55 13 8117 3316
e-mail:  claudef <at> br.ibm.com


dudeja.rajat <at> gmail.com

11/04/2008 11:56 AM

To
jython-users <at> lists.sourceforge.net
cc
Subject
[Jython-users] Hello to everyone. And my first basic question - How        to use a Java class in Jython?





Hi Folks,

This is my first post to the users mailing list. Hello to every one there.
I'm a Jython newbie and I only know Python. I hope to learn many new things from you and try to answer the questions as far as possible asked on this list.

So here I'm with my basic question:

How can use a Java class in Jython?

NB - Java is completely an alien language to me.

Cheers,
Rajat-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users

Attachment (smime.p7s): application/x-pkcs7-signature, 7623 bytes
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users
claudef | 4 Nov 20:18
Picon
Gravatar

Re: Hello to everyone. And my first basic question - How to use a Java class in Jython?


Dear  Rajat,

Letr try o do a Pythonic Javaneese patchwork.  

Step 1 - Compile a valid Java class. Enclosed a sample source for a HelloWorld using Java Swing.  
       
    import javax.swing.*;
    public class HelloWorld
    {
     public static void main(String args[])
     {
     }
     public void showIt()
     {
     JFrame frame = new JFrame("Hello");
     JLabel label = new JLabel("Hello, Welcome to Pythonic Javaneese");
     frame.getContentPane().add(label);
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     frame.pack();
     frame.setVisible(true);
     }
     }

C:\Jython\myprojects\testing>javac HelloWorld.java

C:\Jython\myprojects\testing>dir HelloWorld.*
 Volume in drive C has no label.
 Volume Serial Number is 5CC0-9DEE

 Directory of C:\Jython\myprojects\testing

11/04/2008  05:05 PM               748 HelloWorld.class
11/04/2008  05:00 PM               427 HelloWorld.java
               2 File(s)          1,175 bytes
               0 Dir(s)   4,345,040,896 bytes free


Step 2 - Prepare a Jython script using a Python execution model. The script is stored in the same folder as the Java class code (olamundo.py)  

import sys
import HelloWorld

def runJavaClass():
    ola = HelloWorld()
    ola.showIt()    

def main():
    runJavaClass()  

if __name__ == "__main__":
  main()

       
Step 3 - Run the Jython script to execute the Java class

jython olamundo.py

Step 4  - Check the screen output (this is a Java Swing display)
 


Hope this sample helps. Have fun.

Regards,
Claude

Claude Falbriard
Developer
AMS Hortolândia / SP - Brazil
phone: +55 13 9762 4094
cell:       +55 13 8117 3316
e-mail:  claudef <at> br.ibm.com


dudeja.rajat <at> gmail.com

11/04/2008 01:04 PM

To
claudef <at> br.ibm.com
cc
Subject
Re: [Jython-users] Hello to everyone. And my first basic question - How to use a Java class in Jython?







On Tue, Nov 4, 2008 at 3:02 PM, <dudeja.rajat <at> gmail.com> wrote:


On Tue, Nov 4, 2008 at 2:39 PM, <claudef <at> br.ibm.com> wrote:

Dear Rajat,

The easieat way to use a Java class is through the Jython interpreter. Below a sample code that illustrate some of the concepts.

Step 1 - Import the class pointing to the java package name. To avoid eventual name conflicts, rename a Java  class name during the import. A sample:  
         from java.util import Calendar as JavaCalendar
        from java.text import SimpleDateFormat
 
Step 2 - Use the Java class right from the shelf (no instance creation is required, no "new")
             mytoday = JavaCalendar.getInstance()  
       sdf = SimpleDateFormat("MM/dd/yyyy")
       
Step 3 - Use the Java class methods the same way as you use to do under Python                  
      timev = JavaCalendar.getTime(mytoday)
      stringdate = sdf.format(timev)
      print ("The new age of Java & Python starts at date = " +stringdate)

C:\Jython\myprojects\testing>jython classtest1.py
The new age of Java & Python starts at date = 11/04/2008  

Have fun with Java classes and Jython.

Regards,
Claude

Dear Claude,

Thanks for the detailed description on using the java class.
I have written a sample Hello World class (HelloWorld.class) in Java. Now, I want to import this class in Jython using the statement:

import HelloWorld

Jython is unable to find this class and gives me the following error:
ImportError: no module named HelloWorld

Sorry that was a typo.
Please suggest should I change some enviroment variable or there is anything else?



--
Regrads,
Rajat
Attachment (smime.p7s): application/x-pkcs7-signature, 7623 bytes
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users
Anvesh Reddy | 5 Nov 12:26
Favicon

TypeError: _new_impl()

I keep getting this error when trying to run my code.

TypeError: _new_impl(): expected 2 args; got 1

Strack trace reads something like this.

at org.python.core.Py.TypeError(Unknown Source)
   at org.python.core.PyReflectedFunction.throwError(Unknown Source)
   at org.python.core.PyReflectedFunction.throwArgCountError(Unknown 
Source)
   at org.python.core.PyReflectedFunction.throwError(Unknown Source)
   at org.python.core.PyReflectedConstructor.make(Unknown Source)
   at org.python.core.PyType$2.new_impl(Unknown Source)
   at org.python.core.PyType.invoke_new_(Unknown Source)
   at org.python.core.PyType.type___call__(Unknown Source)
   at org.python.core.PyType.__call__(Unknown Source)
   at org.python.core.PyObject.__call__(Unknown Source)

Iam using jython-2.2.1. Is this some kind of a bug?. I looked into the 
source code of jython 2.2.1. I found this statement  commented out above 
the method where this exception arises.

// xxx temporary solution, type ctr will go through __new__ ...

I was able to compile and run my code successfully with jython 2.1. Any 
help would be greatly appreciated.

Thanks and Regards,
Anvesh Reddy

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
claudef | 5 Nov 12:28
Picon
Gravatar

Re: Hello to everyone. And my first basic question - How to use a Java class in Jython?


Dear Rajat,

I suggest to use a Java package for your applications. The class import works the same way as the Java class loaders. Use the following import syntax:

        from your_java_package_name import your_java_class_name

More information about how to pack and integrate the Jython / Java applications you can find in the Jython language users guide on the web site:  
                http://www.jython.org/Project/userguide.html

Another good reference with useful examples is Mr. Dave Kuhlmans Jython tutorial:
                http://www.rexx.com/~dkuhlman/jython_course_03.html        


As you got now a good picture about the potential use of Jython & Java, lets jump to the next step: Simplifying the code. Type the following source  code into a file like sample1.py or type it interactively into a Jython command prompt. Watch and try this:

import javax.swing as sshwing
from java.lang import Integer
firstNum = sshwing.JOptionPane.showInputDialog("Enter an integer: ")
secondNum = sshwing.JOptionPane.showInputDialog("Enter an integer: ")
num1 = int(firstNum)
num2 = int(secondNum)
sum12 = num1 + num2
sshwing.JOptionPane.showMessageDialog(None,"The sum is " + str(sum12) + ".", "Sum", sshwing.JOptionPane.PLAIN_MESSAGE)

;-)

Enjoy Jython.

Claude

Claude Falbriard
Developer
AMS Hortolândia / SP - Brazil
phone: +55 13 9762 4094
cell:       +55 13 8117 3316
e-mail:  claudef <at> br.ibm.com


dudeja.rajat <at> gmail.com

11/05/2008 07:53 AM

To
claudef <at> br.ibm.com
cc
Subject
Re: [Jython-users] Hello to everyone. And my first basic question - How to use a Java class in Jython?







On Tue, Nov 4, 2008 at 7:18 PM, <claudef <at> br.ibm.com> wrote:

Dear  Rajat,

Letr try o do a Pythonic Javaneese patchwork.  

Step 1 - Compile a valid Java class. Enclosed a sample source for a HelloWorld using Java Swing.  
       
   import javax.swing.*;
   public class HelloWorld
   {
    public static void main(String args[])
    {
    }
    public void showIt()
    {
    JFrame frame = new JFrame("Hello");
    JLabel label = new JLabel("Hello, Welcome to Pythonic Javaneese");
    frame.getContentPane().add(label);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
    }
    }

C:\Jython\myprojects\testing>javac HelloWorld.java

C:\Jython\myprojects\testing>dir HelloWorld.*
Volume in drive C has no label.
Volume Serial Number is 5CC0-9DEE

Directory of C:\Jython\myprojects\testing

11/04/2008  05:05 PM               748 HelloWorld.class
11/04/2008  05:00 PM               427 HelloWorld.java
              2 File(s)          1,175 bytes
              0 Dir(s)   4,345,040,896 bytes free


Step 2 - Prepare a Jython script using a Python execution model. The script is stored in the same folder as the Java class code (olamundo.py)  

import sys
import HelloWorld

def runJavaClass():
   ola = HelloWorld()
   ola.showIt()    

def main():
   runJavaClass()  

if __name__ == "__main__":
 main()

       
Step 3 - Run the Jython script to execute the Java class

jython olamundo.py

Step 4  - Check the screen output (this is a Java Swing display)
 


Hope this sample helps. Have fun.

Regards,
Claude

Dear Claude,

Thanks for such a detailed description. This is really very helpful.
It works.

In case, the script and java class are not located in the same directory then I if add the class location to the CLASSPATH environment variable then is that correct?

Are there any other environment variables that need to set?

Thanks and regards,
Rajat
Attachment (smime.p7s): application/x-pkcs7-signature, 7623 bytes
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users
Alan Kennedy | 5 Nov 12:50
Favicon

Re: TypeError: _new_impl()

[Anvesh]
> I keep getting this error when trying to run my code.

[snip]

> I was able to compile and run my code successfully with jython 2.1. Any
> help would be greatly appreciated.

You're much more likely to get meaningful help if you show us the
actual code you're trying to run that causes the problem. Ideally, you
should post the smallest possible piece of code that illustrates the
problem.

Alan.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
claudef | 5 Nov 17:09
Picon
Gravatar

Re: Hello to everyone. And my first basic question - How to use a Java class in Jython?


Dear Rajat,

 Enclosed some hints to your last question. Hope this gives you an inspiration how to work with the C DLL´s.

 Yes, the Java core implements an access from the JVM to the operating system, giving you access to the command prompt. Under XP, you could place a DOS command, under Linux  you can place for example a 'crontab' (watch the example). Whatever command that is runnable under a OS prompt fits into this API. Enclosed a short code snippet written Jython that illustrate the base concept of  the Java OS Runtime utility and how to deal with the input, output and error data streams.

Another choice is to apply a newer concept of cross-language connectivity and object interchange using the Jython JSR-223 interface. This is only available under Java 6 and works well with Jython. The JSR-223 standard theoretically speaking, should allow you to integrate the C DLL´s. Looks like
this topic isn´t so basic anymore..

Sample Code Snippet for Java Runtime  
from java.lang import Runtime
from java.io import BufferedReader
from java.io import InputStreamReader

# run native OS command
consolelog = ''
mycommand = 'crontab mycronfile'
consolelog += '\nThe shell now runs a native OS command: \n' + mycommand
try:
    System.out.println("starts execution of OS command")
    p = Runtime.getRuntime().exec(mycommand)
    System.out.println("end of execution of OS command")
    stdInput = BufferedReader(InputStreamReader(p.getInputStream()))
    stdError = BufferedReader(InputStreamReader(p.getErrorStream()))
       
    consolelog += "The standard output of the command:\n"
    s = ' '
    while (s != None):
        s = stdInput.readLine()
        if (s is None):
            consolelog += 'end-of-command-printout\n'
         else:  
            consolelog += s + '\n'              
            consolelog += "Standard error display of the command (if any):\n"
            s = ' '
            while (s != None):
               s = stdError.readLine()
               if (s is None):
                   consolelog += ''
               else:    
                   consolelog += s + '\n'
       
            screenoutput = mycommand + '\n' + consolelog
# Catch OS command error returned from Windows or Linux
except:
    screenoutput = mycommand + consolelog + '\n' + 'Invalid OS command, system error detected in command: \n' + mycommand
...

   
Regards,
Claude

Claude Falbriard
Developer
AMS Hortolândia / SP - Brazil
phone: +55 13 9762 4094
cell:       +55 13 8117 3316
e-mail:  claudef <at> br.ibm.com


dudeja.rajat <at> gmail.com

11/05/2008 12:47 PM

To
claudef <at> br.ibm.com
cc
Subject
Re: [Jython-users] Hello to everyone. And my first basic question - How to use a Java class in Jython?







On Wed, Nov 5, 2008 at 11:28 AM, <claudef <at> br.ibm.com> wrote:

Dear Rajat,

I suggest to use a Java package for your applications. The class import works the same way as the Java class loaders. Use the following import syntax:

       from your_java_package_name import your_java_class_name

More information about how to pack and integrate the Jython / Java applications you can find in the Jython language users guide on the web site:  
               http://www.jython.org/Project/userguide.html

Another good reference with useful examples is Mr. Dave Kuhlmans Jython tutorial:
               http://www.rexx.com/~dkuhlman/jython_course_03.html        


As you got now a good picture about the potential use of Jython & Java, lets jump to the next step: Simplifying the code. Type the following source  code into a file like sample1.py or type it interactively into a Jython command prompt. Watch and try this:

import javax.swing as sshwing
from java.lang import Integer
firstNum = sshwing.JOptionPane.showInputDialog("Enter an integer: ")
secondNum = sshwing.JOptionPane.showInputDialog("Enter an integer: ")
num1 = int(firstNum)
num2 = int(secondNum)
sum12 = num1 + num2
sshwing.JOptionPane.showMessageDialog(None,"The sum is " + str(sum12) + ".", "Sum", sshwing.JOptionPane.PLAIN_MESSAGE)

;-)

Enjoy Jython.

Thanks a ton for this.
I'm amazed that how Java and Jython works together. To me it looks the this Jython code is more of a Java code than be a pure Jythonic one. I'm simply amazed how the 2 technologies work so seamlessly.

The reason I opted to write a Java class is that I wanted to call a C DLL in my Jython code. But Jython does not have a capaibility to load (call) a C DLL. So some one suggested me to write a Java Class interface (wrapper) to my C DLl and later call this Java interface from Jython. Thereby, letting Jython access the C DLL.

I have some 4 Dll for which I need to write this Java Interface ( class wrapper). I'm also thinkin on automatically generating this interface by reading the Dll's header file.
Do you know any one who has seen this situation?

It's a nice learning from you.

Thanks and regards,
Rajat
Attachment (smime.p7s): application/x-pkcs7-signature, 7623 bytes
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users
ag356 | 6 Nov 23:39
Picon
Favicon

problem with jython and threads


Hi. Can anyone tell me why the following does not work?

== Begin

import org.python.util.PythonInterpreter;

public class test {

  public static void main(String[] args) throws Exception {
    for (int i = 0; i < 10; i++) {
      new Thread () {
        public void run () {
          String code = "s = \"Hello " +
            Thread.currentThread().getName() +
            "\"\nb = unicode(s,\"utf-8\")\nprint b\n";
          System.out.println("code:\n"+code);
          PythonInterpreter interp = new PythonInterpreter();
          interp.exec(code);
        }
      }.start();
    }
  }

}

== End

I get "LookupError: no codec search functions registered: can't find
encoding" for usually all but one of the threads. Sometimes two or three of
them work.

If I add "import encodings" to the beginning of the script then it works.

Any help would be greatly appreciated! 
--

-- 
View this message in context: http://www.nabble.com/problem-with-jython-and-threads-tp20371245p20371245.html
Sent from the jython-users mailing list archive at Nabble.com.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/

Gmane