Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I could integrate the java/jython from this source.

I downloaded the jython with brew, so the jar file is located in /usr/local/Cellar/jython directory.

I came up with the following script to build the class file into the _build directory, but the issue is that I had to copy the python (jython) source into the directory also to make the integration work.

#!/bin/bash

DIRECTORY="_build"
if [ ! -d "$DIRECTORY" ]; then
    # Control will enter here if $DIRECTORY exists.
    mkdir $DIRECTORY
fi

cp Building.py $DIRECTORY
javac -d _build -cp .:/usr/local/Cellar/jython/2.5.3/libexec/jython.jar *.java
java -cp /usr/local/Cellar/jython/2.5.3/libexec/jython.jar:_build org.jython.book.Main

My question is how to locate the jython source anywhere I like and teach java code to find the jython files?

share|improve this question
up vote 0 down vote accepted

The setupPath() method should be added into the JythonObjectFactory first.

public static void setupPath(String[] paths)
{
    PythonInterpreter interpreter = new PythonInterpreter();

    interpreter.exec("import sys;");
    for (int i = 0; i < paths.length; i++) {
        interpreter.exec(String.format("sys.path.append(\"%s\")", paths[i]));
    }
}

Then, in the Main function, this function should be invoked.

public class Main {
    public static void main(String[] args) {
        JythonObjectFactory factory = JythonObjectFactory.getInstance();
        ArithType a = (ArithType) factory.createObject(ArithType.class, "Arith");

        String[] paths = {"DIRECTORY1", "DIRECTORY2"};
        JythonObjectFactory.setupPath(paths);                        
        ...
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.