How to configure Eclipse to compile with Oracle javac 1.7.0_09?

I am trying to compile the following code snippet:

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 works fine, but with warnings on both methods - " Duplicate method main (String []) in type DuplicateMainExample "

Using javac (java version "1.7.0_09") I have a 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 ?

+7
source share
2 answers

Just because you twice declared the same method with exactly the same signature ... Only one main method for a class needs to be declared.

Eclipse has built 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 old post for more info ...

If you want to compile using javac, you can try using the ant javac adapter from within eclipse ... However, I think ECJ is even better than javac (my opinion) ...

+10
source

Eclipse will never use javac. Its ability to do dynamic highlighting is closely related to its own compiler, which has special capabilities for step-by-step operation.

If you want the IDE to use javac, you can explore intellij.

+4
source

All Articles