问题描述
这是与其他用户之前的一个问题相关的,要求
This is related to an earlier question by a different user, asking How to detect that code is running inside eclipse IDE.
我注意到Eclipse始终使用 javaw
而不是 java
。 (这并不意味着使用 javaw
从Eclipse启动的程序)。
I noticed that Eclipse always launches programs with javaw
rather than java
. (This does not imply a program launched with javaw
was launched from Eclipse).
我可以找到传递的参数使用
I can find the arguments passed using
RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean();
List<String> lst = RuntimemxBean.getInputArguments();
for (int i = 0; i < lst.size(); i++)
System.out.println(lst.get(i));
但这并不告诉我是否使用 java
或 javaw
。
But this does not tell me whether it was launched using java
or javaw
.
- 有没有办法找出是否使用
java
或javaw
? - 为什么Eclipse使用
javaw
启动程序? li>
- Is there any way to find it out whether it was launched using
java
orjavaw
? - Why does Eclipse use
javaw
to launch programs?
推荐答案
将返回 null
,因为唯一的区别在于使用 java
和 javaw
是 javaw
没有关联的控制台窗口。
System.console() will return null
, since the only difference between using java
and javaw
is that for javaw
, there is no associated console window.
这是一个小型测试程序,您可以用来演示:
Here's a small test program you can use to demonstrate that:
import javax.swing.JOptionPane;
public class ConsoleTest {
public static void main(String[] args) {
if (System.console() == null) {
JOptionPane.showMessageDialog(null, "System.console() is null");
} else {
JOptionPane.showMessageDialog(null, "System.console() is not null");
}
}
}
但是,从内部运行Eclipse, System.console()
仍然返回 null
,即使以 java
。
However, when running from within Eclipse, System.console()
will still return null
, even when started with java
.
在Eclipse的启动配置JRE选项卡中,如果将运行时JRE更改为替代JRE ,则可以将Java可执行文件从 javaw
更改为 java
。
In Eclipse's launch configuration, JRE tab, if you change the Runtime JRE to Alternate JRE, you can then change the Java executable from javaw
to java
.
这篇关于我可以找出Java程序是使用java还是javaw启动的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!