33

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

Veera
  • 32,532
  • 36
  • 98
  • 137
  • Is there no more output than that? Can you make it run with verbose logging? – Jon Skeet Aug 03 '10 at 07:22
  • no more output after the error message. Will try with verbose logging. – Veera Aug 03 '10 at 07:25
  • This also happened for me without Eclipse -- jdk-8u241-windows-x64.exe placed a directory in my PATH that only contained java.exe, javaw.exe and javaws.exe. Adding javac.exe to the PATH solved it. – eebbesen Jan 31 '20 at 23:53

19 Answers19

57

I had the same problem and the issue was, in eclipse java.home was referring to JRE instead of JDK. I changed it and the build was successful. You can do the following to change it to JDK:

Preferences > Java > Installed JRE's > Add... For 'JRE Type' select 'Standard VM' > Next > Directory: select your JDK directory (instead of JRE) (in my case: C:\Program Files\Java\jdk1.6.0_16 ), press OK.

Now, you are back at 'Installed JRE's', select the JDK here also.

The below post helped in finding the solution. JAVA_HOME points to the wrong place

Community
  • 1
  • 1
spbala
  • 686
  • 6
  • 7
48

If the accepted answer above doesn't solve the problem for you (as it didn't for me), after updating the java.home to JDK instead of JRE as suggested in the accepted answer above, 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.

This should fix the problem.

aram063
  • 1,067
  • 13
  • 19
  • 4
    +1, this is the more precise answer for those who get this error while running ant. Yes, you need to make sure you have the JDK set as the default JRE, but you need to tell your ant build to use this JDK as well. – Amos M. Carpenter Sep 23 '13 at 01:50
  • Thank you so much!! Using Eclipse Ganymede, I'm using method like the accepted answer but with Eclipse JEE Kepler, I do this method. – Coisox Dec 16 '13 at 03:07
22

I had the same problem and removed the attribute fork from javac and problem was gone.

Avinash
  • 221
  • 2
  • 2
  • Works for me but with warning message: `[javac] Since fork is false, ignoring memoryInitialSize setting. [javac] Since fork is false, ignoring memoryMaximumSize setting.` – chance May 11 '16 at 07:49
  • Worked! There may be more JUnit tests below that say fork="yes" as well you need to change to false or else it will fail with "Process Fork Failed". – Carson Wood Aug 06 '19 at 02:54
7

Maybe the javac problem is because "javac.exe" is not in your System PATH, please edit your system path and add your JDK's /bin directory to it to correct this problem.

Open a shell or command prompt and try typing: javac to check if the system path is set correctly.

Impiastro
  • 848
  • 6
  • 8
  • i have configured the JDK in Eclipse "Installed JRE's" preference page I think Eclipse takes care of putting the javac in claspath. – Veera Aug 03 '10 at 07:27
  • Don't confuse CLASSPATH with SYSTEM PATH, the classpath is used for compilation purposes, system path takes care of system binaries. You can try if the problem is that, just append the JDK bin path to your SYSTEM PATH. – Impiastro Aug 03 '10 at 07:39
  • This is also another way to fix this problem. – prolink007 Apr 11 '12 at 16:14
  • This did it for me. The IT dept at the company I work for has a tendency of making changes that break things. Turns out `JAVA_HOME` got removed from my system's `PATH` at some point. – spaaarky21 Mar 21 '13 at 16:38
  • 1
    In my case there was no javac.exe in bin folder in the java installation path. I reinstalled java and it worked! – actunderdc Nov 06 '19 at 13:54
  • Maybe you had a JRE instead of a JDK. In JRE there is no javac.exe binary. – Impiastro Nov 09 '19 at 17:38
4

Configuring eclipse to point to JDK instead of JRE did not work for me. With further investigation, I solved this problem by stopping the build process from forking. In your build.xml, remove the attribute fork from <javac> tag.

pall
  • 345
  • 3
  • 7
3

I faced the same problem, and here is my advice, maybe it will help someone.
In fact, message Error running javac.exe compiler means that something went wrong. The question is, what exactly. When Ant runs javac task with fork="true" flag, it doesn't print any error details. In my case, it didn't print them even after I added verbose="true", as suggested here. Solution was to add -verbose flag to Ant command line:

ant -verbose

After this, Ant starts printing full error messages, so you are able to fix a problem.

Community
  • 1
  • 1
AlexW
  • 896
  • 7
  • 9
2

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.

dko
  • 197
  • 8
1

I solved this by checking my Environment Variables in my Windows 7. I found that JAVA_HOME is pointing to C:\ Program Files (x86)\Java\jdk1.6.0_31 when it supposed be C:\ Program Files\Java\jdk1.6.0_31. If you want to know how read this

Community
  • 1
  • 1
Uriel Frankel
  • 14,304
  • 8
  • 47
  • 69
1

If you are running ant in eclipse click run as --> Ant second option and choose JDK path and run the build again.

Kannan
  • 33
  • 6
0

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

knb
  • 9,138
  • 4
  • 58
  • 85
0

I've tried everything but nothing worked for me till I've set (fork='no' or fork='false' in your case) and worked for me perfectly

0

I removed fork="true" and I got past that piece of code. What might be interesting to those of you who have this problem is that now, at that line, I get the output:

'Since fork is false, ignoring memoryMaximumSize setting.'

So it may be an issue with memoryMaximumSize if you need to keep your fork="true" setting, as suggested above.

Scala Enthusiast
  • 399
  • 8
  • 18
0

I fixed the problem like this:

My Java home folder had the wrong path. It should have been C:\Program Files (x86)\Java\jdk1.5.0_15 but instead it was C:\Program Files (x86)\Java\jdk1.5.0_15\bin.

Mark
  • 2,380
  • 11
  • 29
  • 49
Salim
  • 2,046
  • 12
  • 13
0

We hit the same issue on a windows build machine whereas locally (on a unix machine) everything worked out. Fork = true didnt helped either, it resulted in a Process fork failed exception also only on the build server

Research

After some research, we had a clue that the classpath might be too long. We recreated the exact folder structure locally on a windows machine and we hit the same issue and we saw that the classpath was way too long (we used -v and -d for details how long it was) and this was the cause of the error.

Solution

The solution was to create a jar, which contains only the manifest with all the libraries, see this answer for more details

Community
  • 1
  • 1
Joker
  • 2,304
  • 25
  • 36
0

Try changing memorymaximumsize="1G" to memorymaximumsize="512M".

fuwaneko
  • 1,155
  • 8
  • 10
0

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.

0

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.

Talha Shahab
  • 189
  • 1
  • 5
0

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.

0

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!!