Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set up other-than-eclipse Java compiler for Eclipse IDE

Tags:

java

eclipse

I noticed that Eclipse IDE (for Java, version 3.5.1) uses it's own java compiler(s), but I can't find how to change it. Is it even possible?

Maybe it's kinda trivial, but after many years of using IntelliJ IDEA I find returning to Eclipse a little bit awkward.

Thanks.

UPDATE: Since more detailed explanation was requested, I'm doing that.

So, recently I was helping out some fellow Java developer and noticed he is using Eclipse w/o Sun's JDK. Since company-wide we are using only Sun's JDKs, I found it rather strange.

It appeared that he has only Eclipse and no additional tools for compiling java code (like javac) are required. This is because Eclipse comes bundled with its own compiler (check this for more details).

By itself I find this feature quite nice, and I believe there were good reasons for that. But I would like all our company developers to use same compiler to generate java bytecode (.class files). And to run this in same JVMs. Just for sake of having as unified environment as possible and eliminating additional environment-specific issues. I have no problem with specifying JRE in Eclipse.

But I failed to find how to change default Java compiler to javac. On the other hand, my primary IDE IntelliJ IDEA allows do that (choose between javac, jikes or eclipse compilers). So I just wanted to know if same is possible in Eclipse or not.

Additionally:

  • No, I have no real problems with Eclipse compiler as such, this is simply matter of being able to choose.
  • I know that Apache Ant and other solutions can be used to compile Java code with any compiler. But here I'm interested in Eclipse and its integrated project building (e.g. menu items under Project menu).
like image 622
Ralkie Avatar asked Nov 12 '10 09:11

Ralkie


3 Answers

What do you want to have? If you want to have the classes created by Sun compiler, you can build them using Ant. Eclipse uses its own compiler because Sun's compiler is not designed to be used in auto-compiled environment.

From the JDT website:

An incremental Java compiler. Implemented as an Eclipse builder, it is based on technology evolved from VisualAge for Java compiler. In particular, it allows to run and debug code which still contains unresolved errors.

Keep in mind that for the library itself, Eclipse will still use the one from Sun's compiler that can be set using the procedure explained by another answers (NimChimpsky and The Elite).

like image 184
nanda Avatar answered Sep 22 '22 02:09

nanda


This is how to add your own JDK/JRE:

  • Goto Windows -> Preferences menu.
  • On Preferences window, in the left drop-down, select, Java -> Installed JREs.
  • Click on the Add bitton (on the right), select Standard VM, then a dialog box will appear with title Add JRE.
  • On JRE home: field, click on directory button and browse to you JRE/JDK root folder. Once selected, it will auto-complete and click finish.

Once you're done, go back to the Preferences window, and tick the radio button of your added JRE/JDK to make it default.

Hope this helps.

like image 33
Buhake Sindi Avatar answered Sep 20 '22 02:09

Buhake Sindi


While I've also looked for this, the only solution I found was to use Maven. With maven-compiler-plugin you can specify the compiler to use, and eclipse will delegate to it. I hope a similar trick can be done for Ant-based projects.

            <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <compilerId>javac</compilerId>
                <encoding>${project.build.sourceEncoding}</encoding>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.codehaus.plexus</groupId>
                    <artifactId>plexus-compiler-javac</artifactId>
                    <version>1.6</version>
                </dependency>
            </dependencies>
        </plugin>

dp4jmaventest is a working demo using this config.

Bug 341842 is an Eclipse feature request for such support.

like image 23
simpatico Avatar answered Sep 19 '22 02:09

simpatico