I am trying to execute a Java class from ant. I first create a jar file for my class and then execute it via ant target. But it is throwing me this error :
Exception in thread “main” java.lang.NoClassDefFoundError: com/abc/utils/ClassName$InnerClass
I am creating a jar in the build file like this:
<jar destfile="${dist.dir}/../lib/jarFile.jar" basedir="${basedir}/classes" includes="com/abc/utils/ClassName.class" />
If I remove the “includes” during the creating of the jar, then everything is fine and I am able to execute the jar file, but I don’t want to include all the files in the jar, since I only need this one class.
Any ideas how to fix this?
That inner class will be a separate file (called
ClassName$InnerClass.class, I think), and you’re explicitly excluding it in your jar definition.Inner classes will manifest themselves as separate class files in the filesystem. Hence just including that one .class file unfortunately will break your deployable, as it’s missing the corresponding inner class.