我知道命令 Environment.currentDirectory in C#给出了当前运行/调试的项目的路径,所以我确信Java中还有一个类似的方式。
所以我问是否有人可以告诉或者给我一个代码,以编程方式找到当前运行/调试项目的路径?
编辑:i am writing eclipse启动加载的插件。 插件添加一个按钮到eclipse的工作台,在插件的代码当我点击按钮我搜索当前的目录路径。
$ b $我的目的是,例如我调试一个项目,然后点击按钮,会弹出一个窗口,显示调试项目的路径,谢谢解决方式两种方式
System.getProperty(user.dir);或这个
code> File currentDirFile = new File(。); String helper = currentDirFile.getAbsolutePath(); String currentDir = helper.substring(0,helper.length - currentDirFile.getCanonicalPath()。length);想法是使用。获取当前文件夹,然后获取绝对位置并从其中删除文件名,因此从
/ home / shark / eclipse / workspace / project / src / com / package / name / bin / Class.class当你删除Class.class你会得到
/ home / shark / eclipse / workspace / project / src / com / package / name / bin /
这是你想要的。
I am trying to locate the path of the current running/debugged project programmatically in Java, I looked in Google and what I found was System.getProperty("user.id"), which didn't get me the project's path.
I know the command Environment.currentDirectory in C# gives the path of the current running/debugged project,so I am sure there must be a similar way in Java, too.
So I am asking if anyone could tell me or give me a code to how locate the path of the currently running/debugged project programmatically?
edit: i am writing plugin which loads with eclipse start. the plugin adds a button to the workbench of eclipse, with in the code of the plugin when i click the button i search for the current directory path.
my purpose is that when for example i debug a project and then click the button, a window will pop up presenting the debugged project's path, thanks
解决方案Two ways
System.getProperty("user.dir");or this
File currentDirFile = new File("."); String helper = currentDirFile.getAbsolutePath(); String currentDir = helper.substring(0, helper.length - currentDirFile.getCanonicalPath().length);The idea is to get the current folder with ".", and then fetch the absolute position to it and remove the filename from it, so from something like
/home/shark/eclipse/workspace/project/src/com/package/name/bin/Class.classwhen you remove Class.class you'd get
/home/shark/eclipse/workspace/project/src/com/package/name/bin/which is kinda what you want.
更多推荐
如何在Java,Eclipse中找到当前项目的路径?
发布评论