获取正在运行的JAR文件的路径将返回"rsrc:./". [英] Getting the path of a running JAR file returns "rsrc:./"
问题描述
我的代码在JAR文件中运行,我需要获取该文件的完整路径. 例如,我的JAR名为example.jar,位于D:\ example \ 因此,我需要通过该jar内的一些代码来获取"D:\ example \ example.jar". 我尝试了很多方法来获取该路径,但是没有一种方法能正常工作.
My code runs inside a JAR file and I need to get the full path of that file. For example, my JAR is called example.jar and is located at D:\example\ So I need to get "D:\example\example.jar" by some code inside that jar. I have tried many methods to get that path, but none of them worked correctly.
其中之一是
getClass().getProtectionDomain().getCodeSource().getLocation().toURI().getPath()
许多人说这对他们有用,但是它为我返回了"rsrc:./".
Many people say that this works for them, but it returns "rsrc:./" for me.
此后,我进行了搜索,发现我的MANIFEST.MF包含以下内容:
I have searched after that and I noticed that my MANIFEST.MF contains this:
Manifest-Version: 1.0
Rsrc-Class-Path: ./
Class-Path: .
Rsrc-Main-Class: Example
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
我不知道这是什么意思,但是如果我删除Rsrc的内容并用它替换其他内容,则说明该jar已损坏.我认为这就是为什么它不起作用的原因.有人知道这意味着什么吗?
I don't know what that means, but if I remove that Rsrc stuff and replace the other things with it, it says the jar is broken. I think this is the reason why it doesn't work. Does anybody know what this means?
PS:我正在使用BAT文件运行JAR.
PS: I'm running my JAR using a BAT file.
推荐答案
我刚刚创建了一个新的工作区,并将每个项目都移到了该工作区中,现在一切正常,我认为这是一个错误或其他问题……谢谢大家为您提供帮助!
I just have created a new workspace and moved every project into it and everything works fine now, I think it was a bug or something...Thank you all for your help!
这篇关于获取正在运行的JAR文件的路径将返回"rsrc:./".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!