How to call Java from Python?

D

Dave Kuhlman

Is JPE (the Python Java Extension) being used widely/actively?

I tried to build it (with Python 2.3.4, j2se 1.4 on Debian
GNU/Linux) and had quite a bit of trouble. And, then, the samples
did not run.

Is there another way to call Java code from Python?

The JPE project does not seem too active lately, or is it?

I need it to run in the Python environment, not the Java
environment. I want to be able to call Java methods from Python.
I don't believe that can be done with Jython, can it? Aren't I
right that Jython runs in the Java environment and on Java VM?

For example, from within the Quixote Web framework, I want to be
able to create Java objects and call their methods.

Thanks in advance for pointers.

Dave
 
F

flacco

Dave said:
For example, from within the Quixote Web framework, I want to be
able to create Java objects and call their methods.

FWIW, i'm kind of in the same boat. i'm switching to python for web
apps, but would sure like to use some of my existing java classes until
time offers an opportunity to convert the code.
 
S

Steve Menard

Dave said:
Is JPE (the Python Java Extension) being used widely/actively?

I tried to build it (with Python 2.3.4, j2se 1.4 on Debian
GNU/Linux) and had quite a bit of trouble. And, then, the samples
did not run.

Is there another way to call Java code from Python?

The JPE project does not seem too active lately, or is it?

I need it to run in the Python environment, not the Java
environment. I want to be able to call Java methods from Python.
I don't believe that can be done with Jython, can it? Aren't I
right that Jython runs in the Java environment and on Java VM?

For example, from within the Quixote Web framework, I want to be
able to create Java objects and call their methods.

Thanks in advance for pointers.

Dave

Seems like my project my project got started at the right time :)

Take a look at JPype http://jpype.sourceforge.net

it aims to do what JPE did (but work).

It is still early in development, and working on win32 exclusively for
now (the linux port should consist only of a few lines of code, but I do
not have a linux meachine readily available). If you have a little C
coding knowledge, you might even contribute it :)

What's more, your's truly is doing his best to answer question and fix
problems as they arise.

I hope this helps,

Steve Menard
 
M

Markus Wankus

Steve said:
Seems like my project my project got started at the right time :)

Take a look at JPype http://jpype.sourceforge.net

it aims to do what JPE did (but work).

It is still early in development, and working on win32 exclusively for
now (the linux port should consist only of a few lines of code, but I do
not have a linux meachine readily available). If you have a little C
coding knowledge, you might even contribute it :)

What's more, your's truly is doing his best to answer question and fix
problems as they arise.

I hope this helps,

Steve Menard

I think there are quite a few of us who are excited about this project
and would like to see this happen. Unfortunately not all of us have the
time (or perhaps the skills) to contribute. If my schedule opens up I
am definitely up for helping out. My end goal - like yours - is to
write Eclipse plug-ins, with the ultimate achievement of a Python IDE in
Eclipse. pyDev is about as close as we have come - but I think it has
reached a 'plateau'.

Markus
 
H

Harry George

Steve Menard said:
Seems like my project my project got started at the right time :)

Take a look at JPype http://jpype.sourceforge.net

it aims to do what JPE did (but work).

It is still early in development, and working on win32 exclusively for
now (the linux port should consist only of a few lines of code, but I
do not have a linux meachine readily available). If you have a little
C coding knowledge, you might even contribute it :)

What's more, your's truly is doing his best to answer question and fix
problems as they arise.

I hope this helps,

Steve Menard

0. Yep, a lot of us need something like this.

1. You could add a link to JPE on the JPype website. Also, it may
have reusable code, idioms, patterns, etc. Broken or not, it was
apparently further along than JPype when it stopped.

2. I'm willing to help, but will have to do it off-hours, at home.
Specifically, the Linux (*NIX) port.

3. I get the impression that the win32-centric part is in javaenv.hpp,
with its use of HINSTANCE. Anything else come to mind?

4. If there are multiple people willing to help, are you setup to
project manage the effort? E.g.:
a) extending the developer's guide documentation as we learn more
b) regression tests
c) prioritizing and coordinating work teams
 
D

Dominic

There is a language interoperability project, which can by found at

http://www.llnl.gov/CASC/components/

"Babel: a tool for mixing C, C++, Fortran77, Fortran90, Python, and Java
in a single application. This is our cornerstone product, representing
90% of our effort. Babel is the foundation for a multilanguage
scientific compoenent framework. We are often called "The Babel Team"
because of this tool's visibility."

However google has not found any references to it
in the comp.lang.python newsgroup which is kind of
strange. Is nobody using it - here? Judging from their
documentation it seems quite reasonable to use
for scientific projects. When they have finished
the java-"server" integration it should even
be perfect.

ciao,
Dominic
 
D

Dave Kuhlman

Steve Menard wrote:

[snip]
Seems like my project my project got started at the right time :)

Take a look at JPype http://jpype.sourceforge.net

it aims to do what JPE did (but work).

It is still early in development, and working on win32 exclusively
for now (the linux port should consist only of a few lines of
code, but I do not have a linux meachine readily available). If
you have a little C coding knowledge, you might even contribute it
:)

What's more, your's truly is doing his best to answer question and
fix problems as they arise.

I hope this helps,

Steve Menard


JPype looks like the real solution to me. And, I hope to use and
help with it.

However, I'm on Linux. So, until JPype supports Linux, I've done
something a bit simpler (or maybe not) in the meantime, here is a
mini-announcement.

generate_wrappers.py
====================

``generate_wrappers.py`` generates support files that enable
Python to use the classes and methods in a Java source code file.

This facility requires and uses ``gcj``, "The GNU Compiler for the
Java Programming Language". It can be used only on platforms that
support ``gcj``, ``gcjh``, and ``libgcj``.

The basic strategy is the following:

1. Use ``gcjh`` to generate a header file for your Java class.

2. Write adapter classes, methods, and functions that use the CNI
(the Compiled Native Interface) API to talk to your Java class.

3. Use SWIG to create Python wrappers for your adapter classes,
methods, and functions.

4. Compile the resulting source code to produce Python extension
(a shared library) that you can be import from Python.

``generate_wrappers.py`` helps you by generating some of the files
you need and by generating a ``Makefile`` that generates others.
*But*, you will need to write the C/C++ adapter classes, methods,
and functions by hand yourself. And, this will require that you
know enough CNI to do so.

Where to get it -- You can find it at:

http://www.rexx.com/~dkuhlman/generate_wrappers.html
http://www.rexx.com/~dkuhlman/generate_wrappers-1.0a.tar.gz

I'm interested in any suggestions, criticisms, ideas, etc.

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,150
Latest member
MakersCBDReviews
Top