JPype - passing to Java main

U

unlikeablePorpoise

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[0]);
}

public void printArgument(String arg) {
System.out.println(arg);
}
}

===========PYTHON===========
from jpype import *

startJVM("C:/Program Files/Java/jdk1.5.0_12/jre/bin/server/jvm.dll","-
Djava.class.path=C:/jpypetest/test/")

com = JPackage("com");
jp = com.JPypeTest();
jp.printArgument('XXXX');
#WANT TO CALL main("arg") HERE!!!!
shutdownJVM()
===============================

What I want is to be able to call main() with an argument from the
python file (using JPype) and have it echo
args[0]. I can get this to work for printArgument(), but not for
main().

Thanks,
Sarah
 
I

Ian Clark

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[0]);
}

public void printArgument(String arg) {
System.out.println(arg);
}
}

===========PYTHON===========
from jpype import *

startJVM("C:/Program Files/Java/jdk1.5.0_12/jre/bin/server/jvm.dll","-
Djava.class.path=C:/jpypetest/test/")

com = JPackage("com");
jp = com.JPypeTest();
jp.printArgument('XXXX');
#WANT TO CALL main("arg") HERE!!!!
shutdownJVM()
===============================

What I want is to be able to call main() with an argument from the
python file (using JPype) and have it echo
args[0]. I can get this to work for printArgument(), but not for
main().

Thanks,
Sarah

Try this:
com.JPypeTest.main("arg")

Ian
 
U

unlikeablePorpoise

Try this:
com.JPypeTest.main("arg")

Ian

Thanks for your suggestion, but it doesn't work (produces an error).

Does anybody else have any ideas?

Thanks,
Sarah
 
U

unlikeablePorpoise

Good point Laurent. Here is the error produced when I try to access
main() using
'com.JPypeTest.main("arg")'

The original code is pasted at the top of this thread. I only added
'com.JPypeTest.main("arg")' which causes the error below

-------------ERROR_-------------
File "tester.py", line 10, in <module>
com.JPypeTest.main("arg")
RuntimeError: No matching overloads found. at src/native/common/
jp_method.cpp:121
----------END ERROR-------------

Thanks,
Sarah
 
G

Gary Duzan

Good point Laurent. Here is the error produced when I try to access
main() using
'com.JPypeTest.main("arg")'

The original code is pasted at the top of this thread. I only added
'com.JPypeTest.main("arg")' which causes the error below

-------------ERROR_-------------
File "tester.py", line 10, in <module>
com.JPypeTest.main("arg")
RuntimeError: No matching overloads found. at src/native/common/
jp_method.cpp:121
----------END ERROR-------------

Thanks,
Sarah

Just a guess, but try com.JPypeTest.main(["arg"]).

Gary Duzan
Motorola HNM
 
A

Alan Kennedy

-------------ERROR_-------------
File "tester.py", line 10, in <module>
com.JPypeTest.main("arg")
RuntimeError: No matching overloads found. at src/native/common/
jp_method.cpp:121
----------END ERROR-------------

I haven't used jpype, but the signature for java main functions is

public static void main (String [] args)

So try com.JPypeTest.main(["arg"])

Note the addition of square brackets to create a *list* of arguments,
which presumably jpype will transform into a java String[].

Alan.
 

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,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top