简体   繁体   English

我的班在罐子里找不到python文件

[英]My class cannot find a python file in the jar

I have a jar file that launches a python script. 我有一个启动python脚本的jar文件。 It works if my jar file is at the root of the working directory. 如果我的jar文件位于工作目录的根目录下,它将起作用。 If I move it out of the working directory, it cannot find the python script anymore. 如果我将其移出工作目录,它将无法再找到python脚本。 Why does my call to find the script file not look inside the jar? 为什么我的查找脚本文件的调用不在jar内? I use ./(the path). 我使用./(路径)。 Why does it automatically look in the working directory? 为什么它会自动显示在工作目录中? I thought it would be self-contained. 我认为这将是独立的。

Reposting my guess as an answer: 重新发布我的猜测作为答案:
Are you looking for the python script as a file? 您是否正在寻找python脚本文件? or as a resource? 还是作为资源? You might want to share more information about your problem because right now all anyone can do is guess. 您可能想分享有关您的问题的更多信息,因为现在任何人都可以做的就是猜测。 My guess is that you're trying to read the Python script as a file, and files don't exist inside of jars. 我的猜测是您正在尝试将Python脚本作为文件读取,而jar中不存在文件。 To solve this, either read the Python script as a file outside of Java, or look for it as a resource inside of the jar. 要解决此问题,可以将Python脚本作为Java外部的文件读取,或者将其作为jar内的资源查找。 If the latter, I'm not sure if you can run the script or not. 如果是后者,我不确定是否可以运行该脚本。

For more, please see this link: stackoverflow: can-i-make-a-jar-execute-a-python-script 有关更多信息,请参见以下链接: stackoverflow:can-i-make-a-jar-execute-a-python-script

Another clever option: stackoverflow: how-do-you-invoke-a-python-script-inside-a-jar-file-using-python 另一个聪明的选择: stackoverflow:您如何在使用Python的jar文件中调用Python脚本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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