0

I am trying to call a python method in java, similar functionality as Unresolved import org.python / working with jython and java?

However, I am using ant to compile and run my files. using import org.python.util will give me this error

package org.python.util does not exist

I can see that python.org.util exists in jython-2.5.0.jar.

So, here is the class path I have in my build.xml ant file:

classpath="${java.class.path}:./jgrapht/lib/jgrapht-jdk1.5.jar:\
    ./jgrapht/lib/jgraph.jar:./jgraphx/lib/jgraphx.jar:\
    ./jython/lib/jython-2.5.0.jar:./colt/lib/colt.jar:."

and I also I added the path to jython jar files to my class path. i.e. looks like echo $path gives me all the required paths. Is there anything missing here that I am not aware of?

Community
  • 1
  • 1
Hasti
  • 239
  • 1
  • 3
  • 17

1 Answers1

0

Try this to make all classes in the package available:

import org.python.util.*;

Or this to include a particular class:

import org.python.util.TemplateAntTask;

EDIT: Also, looks like there is an extra slash after jython-2.5.0.jar in your classpath.

tenorsax
  • 21,123
  • 9
  • 60
  • 107
  • Thank you for your comment. I made the modifications based on your suggestion. However, I still get "package org.python.util does not exist [javac] import org.python.util.*; " – Hasti Feb 20 '12 at 04:32
  • Try to compile one very basic java class with import of python: "javac -cp yourclasspath YourClass.java". Make sure this works. Also, post your ant script. – tenorsax Feb 20 '12 at 04:57
  • I tried to compile a basic code based on your suggestion. If I use javac -cp myclasspath myclass.java it compiles just fine. however, javac myclass.java does not compile and I get the same error as before. Also when I echo $path I do see the correct class path! – Hasti Feb 20 '12 at 07:11
  • You have to use correct classpath for java to compile/run properly. Do not confuse it with OS shell path. Make sure that classpath is specified correctly in you ant script. Check [PATH and CLASSPATH](http://docs.oracle.com/javase/tutorial/essential/environment/paths.html) article. – tenorsax Feb 20 '12 at 07:27