How to use ecj compiler in Netbeans

If you have read my post about why sometimes Eclipse ECJ compiler does not work nicely with other compilers then you maybe also need some cure for that issue.

Few days later I’ve found some, maybe not very nice, solution to get ECJ working with Netbeans IDE. Had no spare time to write about it, but i have few free minutes now and maybe someone needs that stuff also.

I’ve downloaded sources for Netbeans launcher C code (thanks God for Open Source) and modified it so it launches ECJ main class.

Then added one line in main project build.xml file:

<property name="platform.javac" value="<path_to>/ecjexec.exe"/>

(just change <path_to> to where you have saved your launcher)

This will make ant (default Netbeans build system) use ecjexec (thus ECJ) instead of javac.

Oh, you need to do one more thing: add ecj.jar to your system CLASSPATH variable.

Here is some quick’n’dirty C code you can add to Netbeans launcher to make it launch ECJ instead (sorry, no way i can attach exec here):

#include <stdlib.h>
#include <iostream>

#include "jvmlauncher.h"

int main(int argc, char** argv) {

    std::list<std::string> progArgs;
    std::list<std::string> opts;
    for (int i = 1; i < argc; i++) {
        char* arg = argv[i];

    //opts.push_back("-classpath d:/Libs/ecj/ecj.jar");

    JvmLauncher launcher;
    std::string javapath;
    bool java_exists = launcher.getJavaPath(javapath);
    std::cout << "Java: " << java_exists << " " << javapath << std::endl;
    launcher.start("org.eclipse.jdt.internal.compiler.batch.Main", progArgs, opts, true, 0);
    return (0);

You can get original code here: (use platf_launcher, looks like it’s the same code I’ve downloaded few months ago)

Hope it help’s you in some way. Just remember to open/edit launcher in Netbeans 🙂


One Response to How to use ecj compiler in Netbeans

  1. Pingback: JavaPins

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: