Getting Error running javac.exe compiler message, while using Ant in Eclipse

Viewed 95029

When I run my Ant build in Eclipse, I'm getting the following error message and the Ant build fails.

Error Message: Error running javac.exe compiler

Line where the build stops:

<javac destdir="${classes.home}" debug="on" fork="true" memoryinitialsize="512M" memorymaximumsize="1G">
        <classpath refid="classpath"/>
        <src path="${source.home}"/>
</javac>

Has anyone faced a similar problem before? or does anybody know what's wrong here?

System Information: Eclipse Helio, JDK 1.5

19 Answers

The accepted answer didn't work for me. But right-clicking in Ant and setting the Java Runtime Environment (JRE) to the Jave Development Kit (JDK) worked for me.

Abhi Rampal's answer is the step by step the same way I solved the problem on my eclipse.

Go to Run -> External Tools -> External Tools Configuration -> select your build.xml on the left menu -> select JRE tab -> select the JDK(from the dropdown) for Separate JRE radio button option -> Click Run.

Try to free some main memory. Close memory-hungry programs, and stop memory-hungry processes if you can.

For me it was backup libs inside WEB-INF/lib directory. I had multiple lib directory inside the main lib. And the classpath was including them all causing the javac command to become too long.

I removed those directories and it worked for me.

That's a very simple issue. The base directory path has to many subfolders that leads to the actual folder. For e.g.: /folder1/folder2/.../.../folderN/{project}

Decrease the base directory path size and it will compile easily. For e.g.: D:/{project}

Thank me later.

Most of the times, long path to project folder makes the build fail. That's what was found always even when running from Command Line. Just shorten your path to:

{Drive Letter}/{Checkout Project Folder}

and ant commands will surely compile the java JDK.

You need to see the logs for the root cause of the error. Add the runtime argument "-verbose" while running the ant script and it will show the stack trace of the error.

For me, it was throwing for "Error running javac compiler ant The filename or extension is too long ..." I solved it by, installing java in a separate location that is shorter in length, like D:/java/jdk1.8_251.

Also, you can try shortening the eclipse workspace path to a shorter one.

Hope it helps!!

Related