jython and java application

K

KB

Hi there,

Apologies if this is on the wrong group, this is a jython question.
Please redirect me to the correct group if this is in error.

I have a java application that takes no arguements. When I run it, it
spits out output, and finishes.

I am trying to run this java application from jython 2.5.1, JRE6.

I have made simple "Hello World" java classes be callable from a
simple jython script, yet I am stumbling on the java main construct in
the application.

print krbtest.SimpleHistoricTutorial().main() obviously gives me an
args error (expected 1, got 0) as the definition in the java
application is:

public static void main(String[] args)

The jython code is as follows:
import krbtest

# was messing with this to pass a java formatted string but to no
avail

from java.lang import String

print krbtest.SimpleHistoricTutorial().main()

#####

Any advice greatly appreciated! Especially with how to call "main()"
with arguments from jython.

Apologies in advance again if this is the wrong group.
 
S

ShoqulKutlu

I don't know if it's right place but normally main method requires an
args even it is not needed to supply from commandline. Maybe this is a
jython runtime error and requires at least an empty argument. You
could try to pass and empty string array like ['']. I'm not using
jython please use your own notation.

Regards,
Kutlu
 
M

MRAB

KB said:
Hi there,

Apologies if this is on the wrong group, this is a jython question.
Please redirect me to the correct group if this is in error.

I have a java application that takes no arguements. When I run it, it
spits out output, and finishes.

I am trying to run this java application from jython 2.5.1, JRE6.

I have made simple "Hello World" java classes be callable from a
simple jython script, yet I am stumbling on the java main construct in
the application.

print krbtest.SimpleHistoricTutorial().main() obviously gives me an
args error (expected 1, got 0) as the definition in the java
application is:

public static void main(String[] args)

The jython code is as follows:
import krbtest

# was messing with this to pass a java formatted string but to no
avail

from java.lang import String

print krbtest.SimpleHistoricTutorial().main()

#####

Any advice greatly appreciated! Especially with how to call "main()"
with arguments from jython.

Apologies in advance again if this is the wrong group.

I don't know jython, but from the look of it I'd say that you need to
give main() some kind of argument, such as a string or an empty list.
(If you pass an empty jython list to a Java method that's expecting an
array of String, will the Java method receive a zero-length array of
String?).
 
K

KB

Hmmm, for some reason my follow up post didn't make it.

Modified jython script to:

# Eclipse package name for java application
import krbtest

import java.lang as lang
from java.lang import String
from jarray import array

myargs=array([],String)

krbtest.SimpleHistoricTutorial().main(myargs)
****

Now I get:

Traceback (most recent call last):
File "test.py", line 15, in <module>
krbtest.SimpleHistoricTutorial().main(myargs)
at krbtest.SimpleHistoricTutorial.run(SimpleHistoricTutorial.java:27)

at krbtest.SimpleHistoricTutorial.main(SimpleHistoricTutorial.java:
22)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)


java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: com/
bloomberglp/blpapi/Session


I would post the java app but its quite large, but the main defn:

public static void main(String[] args) throws Exception
{
SimpleHistoricTutorial example = new SimpleHistoricTutorial();
example.run();
}


Is pretty vanilla. I have tried making the run() a public method and
call it, all to no avail.

Note, the Java app works fine standalone, I just need to call it from
jython.

Again, any help appreciated.
 
S

ShoqulKutlu

Hi,

I don't know how do you call the java library from within your jython
application it gives java.lang.NoClassDefFoundError
This looks like you referenced jar or whatever else from your jython
application which also needs a class com/bloomberglp/blpapi/Session
in another library file. It might run while running standalone because
the dependent libraries exists where it looks for. For your jython
application you need to make krbtest referenced to the dependent
libraries. It seems you application took a copy of krbtest and other
libraries not available to krbtest there. I hope it helps.

Regards,
Kutlu
 
K

KB

Kutlu,

I already have a first born, else I would name her after you.

You are brilliant. That's what it was. Kudos.

For future ref for fellow boneheads like me, in Eclipse, under Project
properties, Jython Class Path, Add External JAR...

Thanks a million!
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top