By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,345 Members | 1,775 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,345 IT Pros & Developers. It's quick & easy.

JPype - passing to Java main

P: n/a
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

Aug 13 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
un****************@gmail.com wrote:
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

Aug 13 '07 #2

P: n/a
>
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

Aug 14 '07 #3

P: n/a
un****************@gmail.com a écrit :
>Try this:
com.JPypeTest.main("arg")

Ian

Thanks for your suggestion, but it doesn't work (produces an error).
This is where you should have copy/pasted the error.

;-)
>
Does anybody else have any ideas?
Sorry, no.

Aug 14 '07 #4

P: n/a
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

On Aug 14, 8:03 am, Laurent Pointal <laurent.poin...@limsi.frwrote:
unlikeablePorpo...@gmail.com a écrit :
Try this:
com.JPypeTest.main("arg")
Ian
Thanks for your suggestion, but it doesn't work (produces an error).

This is where you should have copy/pasted the error.

;-)
Does anybody else have any ideas?

Sorry, no.

Aug 14 '07 #5

P: n/a
-------------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.

Aug 14 '07 #6

P: n/a
In article <11*********************@d55g2000hsg.googlegroups. com>,
<un****************@gmail.comwrote:
>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
>On Aug 14, 8:03 am, Laurent Pointal <laurent.poin...@limsi.frwrote:
>unlikeablePorpo...@gmail.com a écrit :
>Try this:
com.JPypeTest.main("arg")
>Ian
Thanks for your suggestion, but it doesn't work (produces an error).

This is where you should have copy/pasted the error.

;-)
Does anybody else have any ideas?

Sorry, no.


Aug 15 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.