8

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).
Community
  • 1
  • 1
Ralkie
  • 3,736
  • 3
  • 25
  • 25
  • 1
    can you describe what's awkward? – J-16 SDiZ Nov 12 '10 at 10:00
  • Is there any specific issue you are facing? – Nivas Nov 12 '10 at 10:01
  • Awkwardness of coming back to Eclipse (I was using it for few years, quite long time ago) is somehow different topic, lets focus on primary question. But in general I find configuration of Eclipse not trivial and not very transparent. – Ralkie Nov 12 '10 at 13:16
  • 1
    These is nothing "not trivial". It is just plain "impossible". Eclipse use the build in compiler for code completion, refactoring, quick fix, syntax highlighting, etc -- disabling it means the ide would no longer be usable. – J-16 SDiZ Nov 13 '10 at 01:20

4 Answers4

4

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

nanda
  • 24,458
  • 13
  • 71
  • 90
  • Thanks, but I don't understand how compiler can be set choosing different JRE's. I updated my question, maybe it will be more clear what I meant. – Ralkie Nov 12 '10 at 12:58
  • OK... with that update the answer is easier now. **No.. it can't be done** – nanda Nov 12 '10 at 13:05
  • The part that generates the bytecodes, the compiler itself, isn't tied to a particular set of class libraries. It will use whatever the project's Java Build Path says to compile against. – nitind Sep 26 '12 at 06:05
1

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.

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
  • this change jdk path, not the compiler (ecj) – J-16 SDiZ Nov 12 '10 at 10:00
  • @J-16 SDiZ, true, but the question is ambiguous, you can't change the Eclipse Compiler but you can allow your code to compile to with Oracle JDK. – Buhake Sindi Nov 12 '10 at 10:10
  • 2
    Thanks, but is setting JRE really has something to do with compilation? At least I used to think that Sun's JRE package has no tools like javac included (thats why we have both JRE and JDK, which is not the same). – Ralkie Nov 12 '10 at 13:09
  • Sure, but I meant compiler part, not RT libraries. – Ralkie Nov 12 '10 at 13:25
1

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.

simpatico
  • 10,709
  • 20
  • 81
  • 126
-1

right click project > properties > java compiler

NimChimpsky
  • 46,453
  • 60
  • 198
  • 311
  • Yes, I found this form, but as I understand its more about some additional compilation options, but not about setting different Java compiler implementation (javac). – Ralkie Nov 12 '10 at 13:02