如何检测代码在eclipse IDE中运行 [英] How to detect that code is running inside eclipse IDE
问题描述
如何检测代码是否在eclipse IDE中运行
How to detect that code is running inside eclipse IDE
推荐答案
我不知道一种通用的方式来获得这种代码信息。
I am not aware of a generic way to get this kind of information.
一个建议:
当您在Tomcat中启动Java程序(或Web服务器)时,只需添加一个参数,表明该程序是由Eclipse启动的。
When you start a Java program (or a web server) inside Tomcat, simply add an argument that will indicate that this program is launched by Eclipse.
您可以通过打开打开运行对话框(运行菜单)来执行此操作,然后选择你的应用程序类型并在参数选项卡中添加 -DrunInEclipse = true
。
You can do that by opening the "Open Run Dialog" ("Run" menu), then select your type of application and add in the "Arguments" tab a -DrunInEclipse=true
.
在你的Java代码,你可以检查属性的值:
In your Java code, you can check the value of the property:
String inEclipseStr = System.getProperty("runInEclipse");
boolean inEclipse = "true".equalsIgnoreCase(inEclipseStr);
这样,如果程序没有在Eclipse中运行(或者不幸的是,如果你忘了设置属性)该属性将是 null
,然后布尔 inEclipse
将等于false。
This way, if the program is not running inside Eclipse (or unfortunately if you forgot to set the property) the property will be null
and then the boolean inEclipse
will be equal to false.
这篇关于如何检测代码在eclipse IDE中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!