获取正在运行的 Jar 或 Exe 的名称 [英] Get name of running Jar or Exe

查看:15
本文介绍了获取正在运行的 Jar 或 Exe 的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要做的是获取正在运行的 jar/exe 文件的名称(它在 windows 上是一个 EXE,在 mac/linux 上是 jar).我一直在四处寻找,但似乎无法找到方法.

What I need to do is get the name of the running jar/exe file (it would be an EXE on windows, jar on mac/linux). I have been searching around and I can't seem to find out how.

如何获取正在运行的 Jar 或 Exe 的名称?

How to get name of running Jar or Exe?

推荐答案

希望这可以帮助你,我测试了代码,这会返回完整路径和名称.

Hope this can help you, I test the code and this return you the full path and the name.

也许你想多玩一点代码并给我一些反馈.

Maybe you want to play a little more with the code and give me some feed back.

File(MyClass.class.getProtectionDomain().getCodeSource().getLocation().toURI());‌

这是在 stackoverflow 上的一个类似但不是 == 的问题上发现的如何获取正在运行的 JAR 文件的路径?

This was found on a similar but not == question on stackoverflow How to get the path of a running JAR file?

这篇关于获取正在运行的 Jar 或 Exe 的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆