在Java中指示代码是从IntelliJ / Eclipse等运行还是命令行运行 [英] In Java to indicate if code is running from IntelliJ/Eclipse etc or command line

查看:144
本文介绍了在Java中指示代码是从IntelliJ / Eclipse等运行还是命令行运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如果代码通过Eclipse / IntelliJ或任何其他编辑器运行或从命令行运行,是否有编写programmatic的选项

I would like to know if there is an option to write programmatic if code is running via Eclipse/IntelliJ or any other editor or running from command line

我是想使用System.getProperty(),但有没有任何属性表明它?

I was thinking to use System.getProperty() but is there any property that indicate it?

提前致谢

Nir

推荐答案

没有可靠的方法可以做到这一点。 IDE本身将使用安装在系统上的JRE / JDK或随IDE一起提供的JRE / JDK。 SDK / JVM中没有任何内容专门将自身标识为在IDE中运行。

There is no reliable way to do that. The IDE itself would use a JRE / JDK that is installed on your system or one that comes packaged with the IDE. There is nothing in the SDK / JVM that specifically identifies itself as running from within an IDE.

如果需要在程序中识别此项,请在从IDE运行代码时通过-D标志传递系统属性。此属性的存在(或不存在)可用于确定代码的运行位置。

If you need to identify this in your program, pass a system property through the -D flag when you run the code from the IDE. The presence (or absence) of this property can be used to determine where the code is being run from.

这篇关于在Java中指示代码是从IntelliJ / Eclipse等运行还是命令行运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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