简体   繁体   中英

Jython, how to get the base path of the jar a script is in?

I've packaged some python scripts in a jar using the method described here: Distributing my Python scripts as JAR files with Jython?

This worked fine, but I'm having trouble getting to the base path of the jar my script is in. At the moment, the workaround I've found was to cd to the directory the jar is in and retrieve the path with os.getcwd().

Using os.path.realpath(__file__) gives me /path/to/jar/myapplication.jar/Lib/module/file.py.

Is there a variable like __file__ that would give me /path/to/jar/myapplication.jar instead ?

The reason is I have some configuration file externalized that I would like to retrieve based on a relative path to my application.

似乎sys.exec_prefix是我要寻找的。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM