JPype - passing to Java main

Ian Clark iclark at mail.ewu.edu
Mon Aug 13 19:22:00 EDT 2007


unlikeablePorpoise at 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




More information about the Python-list mailing list