Java – How to include default package in Ant javac Task

antjavajavac

When I:

<javac srcdir="${src}" destdir="${build.classes.dir}" classpathref="classpath">
    <include name="ObjectInDefaultPackage"/>
    <include name="com/mypackage/**"/>
</javac>

It will no longer add compile and add the class ObjectInDefaultPackage that's in the default package (ie. it's not packaged, it's sitting on the man ${src} directory). If I remove the includes it adds it fine, but once I set at least one include/exclude, I can no longer find a way to add it.

If I do:

<javac srcdir="${src}" destdir="${build.classes.dir}" classpathref="classpath">
</javac>

Then it compiles the ObjectInDefaultPackage…

Best Answer

Use this:

<include name="ObjectInDefaultPackage*"/>
<include name="com/mypackage/**"/>

Without slashes, Ant will search in the target directory, which is src. Or use *.java.

It's not recommended to have classes in the default package though.

Related Topic