score:175

Accepted answer
class not found: javac1.8

this error is known to happen with apache ant versions less than 1.9.0 - which aren't compatible with java 8. if you're using a version of ant < 1.9.0, you should update to a 1.9.x release.

here is the related bug report: https://issues.apache.org/bugzilla/show_bug.cgi?id=53347

btw, if you just want to compile with java 8, but don't need to compile any actual java 8 syntax, then you can pass the following argument to javac as a workaround, which would allow you to continue using an older version of ant:

-dbuild.compiler=javac1.7

score:0

i tried all of the other solutions, but none worked. i finally found an approach that worked for me in eclipse:

  • right click on the ant task name, e.g. "compilecustomsrc" in the ant window.
  • choose run as | external tool configurations
  • then on the jre tab, choose separate jre: java se7 or whatever your java 7 is named, then hit apply and then run.

your ant task will be executed, and will build correctly!

score:0

update ant to 1.9.x release as java 8 in incompatible with ant versions less tha 1.9 or after the comand put -dbuild.compiler=javac1.7, see the below:

ant release -dbuild.compiler=javac1.7

score:0

you can download and unzip ant 1.10 on your system and try to chnage the ant home in eclipse for your project to 1.10. it should work, read this for more details. http://devops-badal.blogspot.com/2017/02/class-not-found-javac18-issue-while.html

score:0

sometimes the issue while building the war through ant is also related to java version miss match in build.properties files as build.xml tries to use the java version mentioned in build.compiler property

check whether build.compiler property is same as intended java version.

score:0

you can download a newer version of eclipse, which includes a newer version of ant in the plugins directory. then, copy the ant jar into the older eclipse's plugin directory. eclipse will automatically point to the newer version of ant. this worked for older kepler with newer mars2 for me.

score:0

i had the same problem. and i was able to solve it within the build.xml by setting a property.

<property "build.compiler=javac1.7">

score:1

update ant to 1.9.x release as java 8 in incompatible with ant versions less tha 1.9

score:1

i tried all of the other solutions, but none worked. i finally found an approach that worked for me in eclipse, follow these steps:

  1. right click on the ant task name, e.g. `mybuild.xml in the ant window.

  2. choose run as | external tool configurations.

  3. then on the jre tab, choose separate jre: java jdk7 or whatever your java 7 is named.

  4. hit apply and then run.

your ant task will be executed, and will build correctly!

score:3

java_home = c:\program files (x86)\java\jdk1.5.0_16
jre_home = c:\program files (x86)\java\jre1.5.0_16

your java_home and jre_home are set to the java 1.5 installation hence 1.8 binaries (like javac) are not found. set them to the java 1.8 installation and you should be fine.

score:3

i tried it with eclise and got the same error class not found: javac1.8

i verified the ant version on my system

>ant -version

apache ant(tm) version 1.9.6 compiled on june 29 2015

when i tried to run the build.xml from the command prompt, it worked. then i checked that in the eclipse, it was referring to the older version of the ant.

i simply edited the ant home path in the eclipse and it worked from here also. :)

below is the image from where need to edit the ant path in the eclipse.

  1. right click on the build.xml file
  2. run as
  3. external tool configurations
  4. select the classpath tab

now change the ant home path from here.

enter image description here

score:7

i had this same issue. i had java_home and jre_home set correctly. i also had ant > 1.9.

what i did to fix it is go into eclipse to window -> preferences. expand ant and select runtime. by default the classpath tab should be selected and on the right hand side there is a button called "ant home". click this button and double check it is pointed to your ant folder.

score:14

as a follow-on to kristian holdhus's answer (marked as correct), you can instead use the compiler attribute on the ant javac task. setting compiler="modern" should be both backward (as far back as 1.3) and forward compatible.

this avoids the need to set the java system property named build.compiler. only in the absence of explicitly setting the compiler attribute on the javac task, will ant use the value of the build.compiler as a fallback.


Related Query

More Query from same tag