473,721 Members | 2,259 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JEP and JPype in a single process

skn
Hello,

I have written a very simple java class file, which invokes a Python script
using JEP.

Code snippet:-
-------------------
Jep jep = new Jep(false);
jep.runScript(" C:\\temp\\tests cript.py");
jep.close();

Now inside this Python script I want to make Java calls using JPype.
If I use startjvm() inside this Python script, a Runtime Error (exception)
is thrown.
Also tried attachThreadToJ VM(), but doesn't work, again Runtime Error.

Any clues as to how I could achieve my goal??
The interaction shown below should happen in a single process.

JAVA ==> jep ==> PYTHON ==> jpype ==> JAVA

Regards,
skn
Jul 19 '05 #1
4 2665
On 6/20/05, skn <sk*@skn.com> wrote:
Hello,

I have written a very simple java class file, which invokes a Python script
using JEP. .. . . Now inside this Python script I want to make Java calls using JPype.


I am not familiar with either Jepp or JPype, but I spotted this
snippet on Jepp page (http://jepp.sourceforge.net/):

import jep
FileInputStream = jep.findClass(' java.io.FileInp utStream')
try:
fin = FileInputStream ('adsf')
except jep.FileNotFoun dException:
print 'Invalid file'

Are you sure you need to call JPype?

- kv
Jul 19 '05 #2
skn wrote:
Hello,

I have written a very simple java class file, which invokes a Python script
using JEP.

Code snippet:-
-------------------
Jep jep = new Jep(false);
jep.runScript(" C:\\temp\\tests cript.py");
jep.close();

Now inside this Python script I want to make Java calls using JPype.
If I use startjvm() inside this Python script, a Runtime Error (exception)
is thrown.
Also tried attachThreadToJ VM(), but doesn't work, again Runtime Error.

Any clues as to how I could achieve my goal??
The interaction shown below should happen in a single process.

JAVA ==> jep ==> PYTHON ==> jpype ==> JAVA

Regards,
skn


You're trying to do something I hope to make possible somewhere down the
road ...

As of today, I do not think it is possible. JPype does not provide a way
to initialize the JVM-bridge system except for startJvm .. which seems
to be prohibited when a JVM is already running.

AttachThreadToJ VM will only work once the JVM-bridge system has been
initialize.

I will look into providing a sister method to startJVM to attach to the
currently running JVM instead of starting a new one. IF it does not
require major changes I will release it as 0.5.1. If you'd like you can
submit an enhancement request on the JPype sourceforge page, so this
doesn't get lost.

--
Steve Menard
--------------------
Maintainer of http://jpype.sourceforge.net
Jul 19 '05 #3
Steve Menard wrote:
skn wrote:
Hello,

I have written a very simple java class file, which invokes a Python
script
using JEP.

Code snippet:-
-------------------
Jep jep = new Jep(false);
jep.runScript(" C:\\temp\\tests cript.py");
jep.close();

Now inside this Python script I want to make Java calls using JPype.
If I use startjvm() inside this Python script, a Runtime Error
(exception)
is thrown.
Also tried attachThreadToJ VM(), but doesn't work, again Runtime Error.

Any clues as to how I could achieve my goal??
The interaction shown below should happen in a single process.

JAVA ==> jep ==> PYTHON ==> jpype ==> JAVA

Regards,
skn


You're trying to do something I hope to make possible somewhere down the
road ...

As of today, I do not think it is possible. JPype does not provide a way
to initialize the JVM-bridge system except for startJvm .. which seems
to be prohibited when a JVM is already running.

AttachThreadToJ VM will only work once the JVM-bridge system has been
initialize.

I will look into providing a sister method to startJVM to attach to the
currently running JVM instead of starting a new one. IF it does not
require major changes I will release it as 0.5.1. If you'd like you can
submit an enhancement request on the JPype sourceforge page, so this
doesn't get lost.


OK .. it now works. There are a few caveats that cannot be resolved
until either JEP and JPype can somehow cooperate or I finish what I
started and basically fold the JEP functionality in JPype.

I will release the new functionality in as version 0.5.1. The "gotchas"
are going to be in a readme-jep.txt file.

--
Steve Menard
--------------------
Maintainer of http://jpype.sourceforge.net
Jul 19 '05 #4
skn
Thanks for your prompt reply, Steve.
Just one suggestion, may be the startJVM method's implementation can itself
be changed to check for already existing JVM.
Of course this will also mean a change in shutdownJVM() semantics. If JVM
has been started earlier(not using startJVM()), shutdownJVM() should be a
do-nothing function.

Another question I had was, is there any option to suppress the JVM activity
report that gets displayed. For e.g.,

JVM activity report :
classes loaded : 26
JVM has been shutdown

I know I can do it by re-directing the std err to NUL.
But is there any other option?

With best regards,
skn

"Steve Menard" <fo*@bar.com> wrote in message
news:MX******** ***********@web er.videotron.ne t...
skn wrote:
Hello,

I have written a very simple java class file, which invokes a Python script using JEP.

Code snippet:-
-------------------
Jep jep = new Jep(false);
jep.runScript(" C:\\temp\\tests cript.py");
jep.close();

Now inside this Python script I want to make Java calls using JPype.
If I use startjvm() inside this Python script, a Runtime Error (exception) is thrown.
Also tried attachThreadToJ VM(), but doesn't work, again Runtime Error.

Any clues as to how I could achieve my goal??
The interaction shown below should happen in a single process.

JAVA ==> jep ==> PYTHON ==> jpype ==> JAVA

Regards,
skn


You're trying to do something I hope to make possible somewhere down the
road ...

As of today, I do not think it is possible. JPype does not provide a way
to initialize the JVM-bridge system except for startJvm .. which seems
to be prohibited when a JVM is already running.

AttachThreadToJ VM will only work once the JVM-bridge system has been
initialize.

I will look into providing a sister method to startJVM to attach to the
currently running JVM instead of starting a new one. IF it does not
require major changes I will release it as 0.5.1. If you'd like you can
submit an enhancement request on the JPype sourceforge page, so this
doesn't get lost.

--
Steve Menard
--------------------
Maintainer of http://jpype.sourceforge.net

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
3767
by: F. GEIGER | last post by:
I've dev'ed a Python prototype of an app, that besides the internals making it up has a gui. While test-driven dev'ing the app's internals in Python is fun as usual, dev'ing the GUI is not so funny, at least for me. I guess dev'ing a GUI in a test-driven way is not possible, or is it? I'm using wxPython, so if anyone has an idea... For now most of the time I extend and change the gui things, then run it, do the clicks to go thru the...
14
2875
by: Joachim Boomberschloss | last post by:
Hello, I am working on a project in Python, and I"m currently looking into the possibiliy of writing some of the project"s modules in Java. Given that a large part of the code is already written in Python, using the standard libraries and several extension modules, I am trying to gauge the viability of integration with
3
2294
by: Jim Hargrave | last post by:
I've read that it is possible to compile jython to native code using GCJ. PyLucene uses this approach, they then use SWIG to create a Python wrapper around the natively compiled (java) Lucene. Has this been done before for with jython? Another approach would be to use JPype to call the jython jar directly. My goal is to be able to script Java code using Jython - but with the twist of using Cpython as a glue layer. This would allow...
1
5109
by: benchline | last post by:
I have been trying out jpype for python to java work and love it. It works great on my gentoo box with the java 1.4.2 blackdown sdk. I am now trying it on Red Hat Enterprise Linux 3 for access to business intelligence tools (JasperReports, Mondrian, Pentaho, etc) for which we don't have analogous tools in cpython yet. My idea it to use jpype in a cherrypy application server to tie these java BI tools into a website interface without...
3
2083
by: benchline | last post by:
I would love to be able to use jdbc drivers using the python db 2.0 api and cpython. Has anyone used jpype and zxJDBC (distributed with jython) together? I am trying and what I have tried does not yet work. If I figure anything out that works I will post it here. Thanks
3
4197
by: kelemen.viktor | last post by:
Hello! Im a quite newbie in the python world. I have some problem with packages, i installed the jpype package according to its intructions. To test ive written: everything worked correctly but when i wrote a short script: " from jpype import *
6
4824
by: unlikeablePorpoise | last post by:
I am trying to get JPype to pass a String into a Java class main function. Demonstration code below: =============JAVA============ package com; public class JPypeTest { public static void main(String args) { System.out.println(args);
1
3191
by: oyster | last post by:
As you may know, there is no beautiful and free chart(not plot, you can find the examples at http://www.jfree.org/jfreechart, http://www.rmchart.com) module for python than runs on windows/linux/mac osx. On the other hand, there is a living package(http://www.jfree.org/jfreechart) for java, and it is nice. So what about make the interface to JFreeChart via jpype(http://jpype.sourceforge.net), or rewrite JFreeChart in and for Python to...
1
6378
by: RC | last post by:
Dear Python Experts/Programmers, I'm going to write a Python program to access some Java class methods from our *.jar file. In your opinion, which way is the good (not the best) way to do that? JPype? http://sourceforge.net/projects/jpype
0
8858
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8738
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9230
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9148
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9085
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8026
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5994
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2596
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.