开发者

Binary name in java program compiled by gcj

Is there any way, from within a Java program compiled by gcj, to find out the name of the executable the user ran to start the program?

In C, argv[0] (from inside main) is the name, but in Java, the args array given to main contains only the arguments to the main class. When running with a normal java command line, that makes some sense because the executable would always be java (or java.exe).

When running a Java program which has been compiled by gcj, however, the name of the executable which the user ran might be useful information. Ideally I'd like to find that 开发者_如何学Pythonname without resorting to platform specific approaches like reading /proc (and whatever the equivalent would be for Windows), but perhaps that isn't possible.


After much searching on Google Code Search, I've discovered that the program name is stashed in the gnu.gcj.progname property. Sample program:

public class ProgName {
    public static void main(String... args) {
        System.out.println(System.getProperty("gnu.gcj.progname"));
    }
}

Edited to add: gnu.gcj.progname is documented in libgcj Runtime Properties too, so luckily this isn't just an internal implementation detail.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜