Resolving Ant javac “class file has wrong version” issues

Ever run an ANT build in eclipse and it works just fine, but as soon as you run it outside of eclipse you get something like…

class file has wrong version 51.0, should be 49.0

The issue is likely that you need to “fork” in your javac task…

Before (with error)

javac srcdir="${build.path}" 
   verbose="true" 
   includeantruntime="false" 
   includejavaruntime="false"

After (no error)

javac srcdir="${build.path}" 
   verbose="true" 
   includeantruntime="false" 
   includejavaruntime="false" 
   fork="yes"

Hopefully this can save you about 2 hours some day!

Please remember to subscribe to the newsletter to stay up to date!

You or someone you know looking to buy or sell?
Disclaimer: Thoughts and opinions are my own, and do not reflect the views of any employer, family member, friend, or anyone else. Some links may be affiliate links, but I don't link to anything I don't use myself. You would think this should be self evident these days, but apparently not...

Leave a Reply