Can you tell on runtime if you're running java from within a jar?

后端 未结 8 1554
星月不相逢
星月不相逢 2020-12-09 14:54

I have an application that some of my users run from Eclipse, and others run it by using a jar file.

I want some actions to be done when running from within the jar,

8条回答
  •  佛祖请我去吃肉
    2020-12-09 15:08

    You could check the system class path property for the Equinox launcher:

    if (System.getProperty("java.class.path").contains("org.eclipse.equinox.launcher")) {
        System.out.println("You're running inside Eclipse");
    }
    

    There are some other potential properties that you may check for, which you can find in Eclipse through Help -> About -> Configuration Details.

    Jon's answer is good if you want to know whether you'r running from a JAR versus running from a bunch of class files. But if you use a JAR in both cases then it won't tell you what you need.

提交回复
热议问题