在jython中获取jython-[standalone-]x.x.x.jar执行文件目录

新建test.py文件:

#coding:utf-8

def find_jython_jar_path():
    try:
        from org.python.util import jython
        return jython().getClass().getProtectionDomain().getCodeSource().getLocation().getPath()
    except:
        raise Exception("Cannot find jython jar")

print find_jython_jar_path()

windows命令行下测试:

>chcp 437
Active code page: 437
>java -jar D:\devenv\maven_repository\org\python\jython-standalone\2.7.1\jython-standalone-2.7.1.jar .\test.py                                                                                                         
/D:/devenv/maven_repository/org/python/jython-standalone/2.7.1/jython-standalone-2.7.1.jar

 

你可能感兴趣的:(java)