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

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

问题描述

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

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

在Eclipse中它工作正常,但是在两种方法 - DuplicateMainExample类型中的重复方法main(String [])



使用 javac (java version1.7.0_09)我有一个编译错误:

 > javac DuplicateMainExample.java 
DuplicateMainExample.java:8:error:不能在DuplicateMainExample
中声明main(String ...)和main
(String [])public static void main(String ... args){
^
1错误

如何在Eclipse中使用 javac

解决方案

只是因为您已经使用完全相同的签名两次声明了相同的方法。应该声明只有一个主要的方法。



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



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



如果你想用javac编译你可以尝试使用ant javac适配器从eclipse ...但是我认为ECJ甚至比javac(我的意见)更好...


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"

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

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 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 ...

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) ...

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

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