|
View:
New views
9 Messages
—
Rating Filter:
Alert me
|
|
|
JPype // TypeError // Getting it to work with Jar file for first timeHello,
I am trying to use jpype, but after several hours/days, I still cannot get it to work. I get a TypeError --- Package is not Callable error. (See below) I already have done a good workable chunk of code I wrote in Java that implements steam table calculations. After a few weeks of playing with Python, I see that as much more promising for me, and want to switch. But rewriting all of this java code a second time is not going to happen. If I can get jpype to make this ONE link to my existing Java code for me, I can move forward. I would appreciate any help as I can not find the answer in my internet searches. -------------------------------------------------------------------------- I get the following error (IDLE): Traceback (most recent call last): File "C:\Python26\testPype.py", line 16, in <module> myClass = steamPackage.SteamPoint() File "C:\Python26\lib\site-packages\jpype\_jpackage.py", line 53, in __call__ raise TypeError, "Package "+self.__name+" is not Callable" TypeError: Package de.engineering.steam.SteamPoint is not Callable ---------------------------------------------------------------- Here is my Python Code: import jpype jvmPath = "C:\\Program Files\\Java\\jdk1.5.0_13\\jre\\bin\\client\\jvm.dll" options = "-ea" jarPath = "-DJava.class.path=C:\\javaNetBeans\\Projects\\de.engineering.steam\\dist\\de.engineering.steam.jar" jpype.startJVM(jvmPath,options, jarPath) packageName="de.engineering.steam" steamPackage = jpype.JPackage(packageName) myClass = steamPackage.SteamPoint() FYI, I have tried various variations that I could think of, but still no luck myClass = steamPackage.SteamPoint #produces no error, but I can do nothing with this myClass = steamPacakge.NonExistentClass #also produces no error, and just as useless! myClass = steamPackage.SteamPoint(1,40,400) # TypeError as above myClass = steamPackage.SteamPoint.SteamPoint() # TypeError as above --------------------------------------------------------------------- Here is a summary of the Java code for the class. This is stored in a .jar file (see python code). As stated, this single Java class is the gateway to all of my Java code stored in that jar file ... so all I need is to access the functionality in this one class. package de.engineering.steam; import de.engineering.steam.IAPWSF97.*; public class SteamPoint { private double p, t, h, s, v, x; ///etc. etc. //blank constructor - not important public SteamPoint() {} //the *real* constructer public SteamPoint(int switchCode, double d1, double d2) {...} //the methods I need to access after a sucessful construction creation /**Returns the pressure (bara)*/ public double p() {return p;} //etc.... etc... etc.. } THANK YOU for any help! Timothy (plovet) |
|
|
Re: JPype // TypeError // Getting it to work with Jar file for first timeHi Timothy,
diagnosing this kind of problem is currently one of JPype main weaknesses (in part because the JVM provides no help whatsoever). As far as I can see, your code is correct, so best I can do is offer a few suggestions to try and move forward. For sure, as your script currently stands, JPype is unable to find the de.engineering.steam.SteamPoint class, and thus treats it as a package. 1) double check you jar path. you can safely use / instead of \\, removing a possible escaping issue 2) Double check the jar really is where you think it is. 3) Make sur you jar has no dependency on other jars. What really triggers the problem is a ClassNotFoundException, and this can be for the SteamPoint class as well as for any class it needs underneath. 4) To validate your classpath, print the value of the java.class.path system property. Simply do print jpype.java.lang.System.getProperty("java.class.path"). let me know if this helps. Steve Menard ------------------------------ Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Rick Cook, The Wizardry Compiled ------ There are two major products that come out of Berkeley: LSD and UNIX. We don't believe this to be a coincidence. -- Jeremy S. Anderson On Tue, Jan 18, 2011 at 3:11 PM, plovet <tr03@...> wrote:
------------------------------------------------------------------------------ Protect Your Site and Customers from Malware Attacks Learn about various malware tactics and how to avoid them. Understand malware threats, the impact they can have on your business, and how you can protect your company and customers by using code signing. http://p.sf.net/sfu/oracle-sfdevnl _______________________________________________ Jpype-users mailing list Jpype-users@... https://lists.sourceforge.net/lists/listinfo/jpype-users |
|
|
Re: JPype // TypeError // Getting it to work with Jar file for first timeWe've had issues w/ JPackage, so we always use JClass - maybe that'll work for you, too?
from jpype import * clz = JClass("de.engineering.steam.SteamPoint") instance = clz() On Tue, Jan 18, 2011 at 3:27 PM, Steve Ménard <menard.steve@...> wrote: Hi Timothy, ------------------------------------------------------------------------------ Protect Your Site and Customers from Malware Attacks Learn about various malware tactics and how to avoid them. Understand malware threats, the impact they can have on your business, and how you can protect your company and customers by using code signing. http://p.sf.net/sfu/oracle-sfdevnl _______________________________________________ Jpype-users mailing list Jpype-users@... https://lists.sourceforge.net/lists/listinfo/jpype-users |
|
|
Re: JPype // TypeError // Getting it to work with Jar file for first timeHello Steve,
Thanks for the quick reply and good suggestions. It might well be #3) - Jar Dependencies ...... As an aside, before I posted, I saw that your name repeatedly was answering and helping reply to many other posts. So I am pleased to have you help me as well. :) Thanks, I will work on your suggestions and let you know afterwards what I come up with...... Timothy
|
|
|
Re: JPype // TypeError // Getting it to work with Jar file for first timeGood suggestion Raj.
JClass is required for those few cases where the Java naming convention is not strictly followed (i.e. inner classes). However in this case I see no reason why JPackage would fail, and using JPackage makes for more "pythonic" code. As an aside Raj, I would definitely be interested in what kind of problems you've had with JPackage that JClass fixed (JPackage uses JClass underneath). Steve Menard ------------------------------ Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Rick Cook, The Wizardry Compiled ------ There are two major products that come out of Berkeley: LSD and UNIX. We don't believe this to be a coincidence. -- Jeremy S. Anderson On Tue, Jan 18, 2011 at 3:32 PM, Raj Bakhru <rbakhru@...> wrote: We've had issues w/ JPackage, so we always use JClass - maybe that'll work for you, too? ------------------------------------------------------------------------------ Protect Your Site and Customers from Malware Attacks Learn about various malware tactics and how to avoid them. Understand malware threats, the impact they can have on your business, and how you can protect your company and customers by using code signing. http://p.sf.net/sfu/oracle-sfdevnl _______________________________________________ Jpype-users mailing list Jpype-users@... https://lists.sourceforge.net/lists/listinfo/jpype-users |
|
|
Re: JPype // TypeError // Getting it to work with Jar file for first timeHello Steve,
Your suggestions were good, but success still eludes me. Below is a full summary of what I have checked and done since your suggestions. It might be something with the classPath, see #4. Does any of that suggest anything to you? Thanks for you support. Timothy ------------------------------------------------------------- 1) double check you jar path. you can safely use / instead of \\, removing a possible escaping issue a) Double-Checked and Triple Checked. b) Ok. Changed the \\ to /. 2) Double check the jar really is where you think it is. a) Check. Check. Check. Every letter of the Path is correct. 3) Make sur you jar has no dependency on other jars. What really triggers the problem is a ClassNotFoundException, and this can be for the SteamPoint class as well as for any class it needs underneath. a) My jar does have dependencies on other jars. In fact, the first import statement is calling a jar. These are all stored in a 'lib' subfolder and access routines I need ..... b) To check if that is the problem, I created a simple test class 'TestSteam' that works without any dependencies. No Success. 3a) Not having had any success above, I have done the following: a) Made a New Class <TestSteam()> in a New Package <package junkTest> in A New Jar File <junkTest.jar>. b) I moved the jar file to an upper level folder with a simple path. "C:\Python26\junkTest.jar" c) Tested via the command line that that the main method works properly "java -cp junkTest.jar junkTest.TestSteam" d) Wrote a python script to access it. Result is the same Error as before "TypeError...not callable" import jpype jvmPath = "C:/Program Files/Java/jdk1.5.0_13/jre/bin/client/jvm.dll" options = "-ea" jarPath = "-DJava.class.path=C:/Python26/junkTest.jar" jpype.startJVM(jvmPath,options, jarPath) packageName="junkTest" myPackage = jpype.JPackage(packageName) print "<myPackage:>", myPackage print "java.class.path",jpype.java.lang.System.getProperty("java.class.path") #see below myPackage.TestSteam(1,40.0,400.0) e) Resulting Error is as before: Traceback (most recent call last): File "C:/Python26/testPype3.py", line 20, in <module> myPackage.TestSteam(1,40.0,400.0) File "C:\Python26\lib\site-packages\jpype\_jpackage.py", line 53, in __call__ raise TypeError, "Package "+self.__name+" is not Callable" TypeError: Package junkTest.TestSteam is not Callable 4) To validate your classpath, print the value of the java.class.path system property. Simply do print jpype.java.lang.System.getProperty("java.class.path"). a) When I put this at the python prompt I get an empty string back: <u''> b) I am not a classPath expert. Having the jar file in the folder I am using, what should I be expecting here?? 5) FYI - For Compeletness, this is the junkTest.TestSteam test class package junkTest; public class TestSteam { private double p, t, h, ph, s, v, x; public TestSteam() {} public TestSteam(int switchCode, double d1, double d2) { switch (switchCode) { case 1: { //System.out.println("Selected PH"); p = d1; h = d2; ph = d1*d2; break; } } } public double p() {return p;} public double h() {return h;} public double t() {return t;} public String stringDescription() {return "P:"+p+" H:"+h+" PH:"+ph;} public static void main(String[] args) { TestSteam t1 = new TestSteam(1, 40, 400); System.out.println("MainTest:"+t1.stringDescription()); } // end main } // end class 6) Random Thoughts a) Could it be the type jar file? Are all jar files equal? Does NetBeans make different types of jar files, based on different project types?? b) Could it be something to do with IDLE? FYI, IDLE does seem to crash quite a bit when I am using jpype. I have assumed that the reason has to do with my *failure* to successfuly connect the jar file, and resulting bugs. However, maybe there is another problem..... |
|
|
Re: JPype // TypeError // Getting it to work with Jar file for first timeDear Steve, Raj,
Below is my result of my trying to use JClass. It is clear that the class is not being found, but I am at a loss to explain. FYI, I also tried changing the options to the use the java options that I typically use when accessing a jar file via a batch file. (I do not see that it makes any difference) Thanks, Timothy ----------Error Message--------- Warning (from warnings module): File "C:\Python26\lib\site-packages\jpype\_pykeywords.py", line 18 import sets DeprecationWarning: the sets module is deprecated Traceback (most recent call last): File "C:/Python26/testPype3a.py", line 11, in <module> myClass = jpype.JClass(className) File "C:\Python26\lib\site-packages\jpype\_jclass.py", line 54, in JClass raise _RUNTIMEEXCEPTION.PYEXC("Class %s not found" % name) java.lang.ExceptionPyRaisable: java.lang.Exception: Class junkTest.TestSteam not found ----------Python Code--------- #testPype3a.py import jpype jvmPath = "C:/Program Files/Java/jdk1.5.0_13/jre/bin/client/jvm.dll" options = ("-Xms64m", "-Xmx512m", "-cp") # "-ea" jarPath = "-DJava.class.path=C:/Python26/junkTest.jar" jpype.startJVM(jvmPath,options, jarPath) className="junkTest.TestSteam" myClass = jpype.JClass(className) myInstance = myClass() ----------Jar File--------- I used the new jar file in my C:\Python26 folder (see prev. post). |
|
|
Re: JPype // TypeError // Getting it to work with Jar file for first timeI think I got it :)
It's really one of those very small details ... import jpype jvmPath = "C:/Program Files/Java/jdk1.5.0_13/jre/bin/client/jvm.dll"
options = "-ea" jarPath = "-DJava.class.path=C:/Python26/junkTest.jar" jpype.startJVM(jvmPath,options, jarPath) I believe the problem is here : -DJava.class.path java's system variable are case-sensitive ... so the J would be a problem (I checked, the capital J was also in your first example). try with -Djava.class.path and with some luck that'll solve your problem. Steve Menard ------------------------------ Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Rick Cook, The Wizardry Compiled ------ There are two major products that come out of Berkeley: LSD and UNIX. We don't believe this to be a coincidence. -- Jeremy S. Anderson On Tue, Jan 18, 2011 at 5:39 PM, plovet <tr03@...> wrote:
------------------------------------------------------------------------------ Protect Your Site and Customers from Malware Attacks Learn about various malware tactics and how to avoid them. Understand malware threats, the impact they can have on your business, and how you can protect your company and customers by using code signing. http://p.sf.net/sfu/oracle-sfdevnl _______________________________________________ Jpype-users mailing list Jpype-users@... https://lists.sourceforge.net/lists/listinfo/jpype-users |
|
|
Re: JPype // TypeError // Getting it to work with Jar file for first timeSteve,
You got it! Jeez! Sorry for not having caught that myself, but THANK YOU for the help! I have done some tests, and am pleased to say that jpype (both JPackage and JClass) now works wonderful and fast! :) Also, I appear not to have any problem with the jar "dependancies" problem that you mentioned. Even though I have dependancies on two additional jar files, neither of which I have named to JPype, the data works fine. My main class SteamPoint immediately calls a second jar IAPWSF97 - and the data return is correct. Now, I can use my java steam data in Python. Thanks again and regards, Timothy |
| Free embeddable forum powered by Nabble | Forum Help |