如何配置 Eclipse 以使用 Oracle javac 1.7.0_09 进行编译? [英] How to configure Eclipse to compile using Oracle javac 1.7.0_09?

查看:27
本文介绍了如何配置 Eclipse 以使用 Oracle javac 1.7.0_09 进行编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编译以下代码:

I am trying to compile following piece of code:

public class DuplicateMainExample {
    public static void main(String[] args) {
        System.out.print("A1");
    }

    public static void main(String... args) {
        System.out.print("A2");
    }   
}

在 Eclipse 中它工作正常,但对两种方法都有警告 - Duplicate method main(String[]) in type DuplicateMainExample"

In Eclipse it's working fine, but with warnings on the both methods - "Duplicate method main(String[]) in type DuplicateMainExample"

使用 javac(java 版本1.7.0_09")我有一个编译错误:

Using javac (java version "1.7.0_09") I have an compilation error:

>javac DuplicateMainExample.java
DuplicateMainExample.java:8: error: cannot declare both main(String...) and main
(String[]) in DuplicateMainExample
        public static void main(String... args) {
                           ^
1 error

如何在 Eclipse 中使用 javac 进行编译?

How to compile in Eclipse using javac?

推荐答案

很简单,因为你已经用完全相同的签名两次声明了同一个方法......只应该声明一个类的主要方法.

Simply because you have declared the same method with exactly the same signature twice ... Only one main method for class should be declared .

Eclipse 已经嵌入了自己的编译器,在两种主要方法的情况下,它得到最后一个,eclipse 编译器和 javac 编译器是两种不同的编译器...

Eclipse have embedded its own compiler and in the case of two main methods it gets the last one, the eclipse compiler and the javac compiler are two different compilers ...

看看这篇较旧的帖子 了解更多信息...

Take a look at this older post for more information ...

如果你想用 javac 编译你可以试试 在 eclipse 中使用 ant javac 适配器 ...不过我认为 ECJ 甚至比 javac 更好(我认为)...

If you want to compile with javac you could try using the ant javac adapter from within eclipse ... However i think that ECJ is even better than javac(my opinion) ...

这篇关于如何配置 Eclipse 以使用 Oracle javac 1.7.0_09 进行编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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