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?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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.*; "
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.
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!
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 article.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.