Hello, I am completely new to Open Trip Planner, Java, and Jython and pretty new to Python.
I have had success using Open Trip Planner in the browser and would like to move on to doing analytical work in batch mode.
I tried using Eclipse, but I think that is beyond me for now.
So, for example, in C:\OpenTripPlanner\target I now have:
otp-0.19.0-SNAPSHOT.jar
otp-0.19.0-SNAPSHOT-shaded.jar
otp-0.19.0-SNAPSHOT-sources.jar
I also downloaded the standalone version of Jython 2.7.0 based on the recommendations in the "Launching a script from OTP" section of the
Scripting documentation and copied that into C:\OpenTripPlanner as well:
jython-standalone-2.7.0
(Also tried with jython-standalone-2.5.4-rc1.jar, but that didn't seem to matter)
In addition, I put the accessibility script ("accessibility.py") in the same folder (C:\OpenTripPlanner) and have a default Graph.obj there of Chicago.
I have versions of the Chicago Census Blocks shapefile and the grocery stores' XY coordinates, but haven't reached the point of using those files yet due to other issues.
For reference, Environment Variables and Values:
JAVA_HOME: C:\Program Files\Java\jdk1.8.0_60
JYTHON_HOME: C:\jython2.7.0*
*Should JYTHON_HOME be set to the path to the folder location of jython-standalone-2.7.0.jar instead or does that defeat the purpose of the standalone version?
When trying to run the script with a Java command (I have not had luck with the
suggested Jython command like "jython -Dpython.path=otp-x.y.z-shaded.jar myscript.py") that includes the OTP and Jython JAR files in the classpath, I get an error saying, among other things, that 'OtpsEntryPoint' is not defined:
C:\OpenTripPlanner\target>java -cp otp-0.19.0-SNAPSHOT-shaded.jar;jython-standalone-2.5.4-rc1.jar org.opentripplanner.standalone.OTPMain --script accessibility.py
16:26:22.185 INFO (OTPServer.java:38) Wiring up and configuring server.
16:26:22.202 INFO (BSFOTPScript.java:60) Running script C:\OpenTripPlanner\target\accessibility.py
16:26:22.206 DEBUG (BSFManager.java:399) BSFManager:declareBean
16:26:22.206 DEBUG (BSFManager.java:752) BSFManager:registerBean
16:26:22.207 DEBUG (BSFManager.java:483) BSFManager:exec
16:26:22.207 DEBUG (BSFManager.java:674) BSFManager:loadScriptingEngine
16:26:22.208 DEBUG (BSFManager.java:556) BSFManager:getClassPath
16:26:22.208 DEBUG (BSFManager.java:548) BSFManager:getClassLoader
16:26:23.219 ERROR (BSFManager.java:499) Exception :
java.security.PrivilegedActionException: null
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0
_60]
at org.apache.bsf.BSFManager.exec(BSFManager.java:491) ~[otp-0.19.0-SNAP
SHOT-shaded.jar:1.1]
at org.opentripplanner.scripting.impl.BSFOTPScript.run(BSFOTPScript.java
:66) [otp-0.19.0-SNAPSHOT-shaded.jar:1.1]
at org.opentripplanner.standalone.OTPMain.run(OTPMain.java:153) [otp-0.1
9.0-SNAPSHOT-shaded.jar:1.1]
at org.opentripplanner.standalone.OTPMain.main(OTPMain.java:88) [otp-0.1
9.0-SNAPSHOT-shaded.jar:1.1]
Caused by: org.apache.bsf.BSFException: exception from Jython:
Traceback (most recent call last):
File "<string>", line 19, in <module>
NameError: name 'OtpsEntryPoint' is not defined
at org.apache.bsf.engines.jython.JythonEngine.exec(JythonEngine.java:146
) ~[otp-0.19.0-SNAPSHOT-shaded.jar:1.1]
at org.apache.bsf.BSFManager$6.run(BSFManager.java:493) ~[otp-0.19.0-SNA
PSHOT-shaded.jar:1.1]
... 5 common frames omitted
Exception in thread "main" java.lang.RuntimeException: org.apache.bsf.BSFExcepti
on: exception from Jython:
Traceback (most recent call last):
File "<string>", line 19, in <module>
NameError: name 'OtpsEntryPoint' is not defined
at org.opentripplanner.standalone.OTPMain.run(OTPMain.java:159)
at org.opentripplanner.standalone.OTPMain.main(OTPMain.java:88)
Caused by: org.apache.bsf.BSFException: exception from Jython:
Traceback (most recent call last):
File "<string>", line 19, in <module>
NameError: name 'OtpsEntryPoint' is not defined
at org.apache.bsf.engines.jython.JythonEngine.exec(JythonEngine.java:146
)
at org.apache.bsf.BSFManager$6.run(BSFManager.java:493)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.bsf.BSFManager.exec(BSFManager.java:491)
at org.opentripplanner.scripting.impl.BSFOTPScript.run(BSFOTPScript.java
:66)
at org.opentripplanner.standalone.OTPMain.run(OTPMain.java:153)
... 1 more
Out of curiosity, I wanted to see how far I could get submitting lines one by one in interactive Jython.
In interactive Jython, I am able to successfully import packages and classes (the lines below all work)...
import sys
sys.path.append('C:\\OpenTripPlanner\\target\\otp-0.19.0-SNAPSHOT-shaded.jar')
sys.path.append('C:\\OpenTripPlanner\\target\\jython-standalone-2.7.0.jar')
from org.opentripplanner.scripting.api import *
otp = OtpsEntryPoint.fromArgs([ "--graphs", "." ])
...but I am unable to assign values to functions.
For example, "r.setModes('WALK')" gives this error:
"TypeError: setModes(): 1st arg can't be coerced to org.opentripplanner.routing.core.TraverseModeSet"
Same result when trying "r.setModes('WALK,TRANSIT')" which I have seen elsewhere.
Some questions:
- Do I need to somehow incorporate the opentripplanner-jython bindings into this process before running the accessibility script?
- What have I set up incorrectly that is making the Java command unable to use OtpsEntryPoint, but allows interactive Jython to use OtpsEntryPoint with no problem?
- Could anyone point me to a guide to batch scripting for beginners in a recent version of Open Trip Planner in a Windows environment?
Any advice on what I am missing would be greatly appreciated!
I'm hoping other beginners might learn from my mistakes and your knowledge.