简体   繁体   English

如何使用Oracle javac 1.7.0_09配置Eclipse进行编译?

[英]How to configure Eclipse to compile using 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");
    }   
}

In Eclipse it's working fine, but with warnings on the both methods - " Duplicate method main(String[]) in type DuplicateMainExample " 在Eclipse中,它工作正常,但在两个方法上都有警告 - “ DuplicateMainExample ”中的“ Duplicate method main(String [])

Using javac (java version "1.7.0_09") I have an compilation error: 使用javac (java版“1.7.0_09”)我有一个编译错误:

>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

How to compile in Eclipse using javac ? 如何使用javac在Eclipse中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 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 ... Eclipse嵌入了自己的编译器,在两个主要方法的情况下,它得到了最后一个,eclipse编译器和javac编译器是两个不同的编译器......

Take a look at this older post for more information ... 看看这篇较旧的帖子了解更多信息......

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) ... 如果你想用javac编译你可以尝试在eclipse中使用ant javac适配器 ...但是我认为ECJ甚至比javac更好(我的意见)......

Eclipse will never use javac. Eclipse永远不会使用 javac。 Its ability to do dynamic highlighting is intimately connected with its own compiler, which has special abilities to operate incrementally. 它能够进行动态突出显示与其自己的编译器密切相关,后者具有逐步增强操作的特殊功能。

If you want an IDE that uses javac, you might investigate intellij. 如果您想要一个使用javac的IDE,您可以调查intellij。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM