java - Why does ant think package doesn't exist? -


i have following directory structure:

myapp/     src/main/java/         com/             myapp/                 api/                     ifizz                     fizzloader                 impl/                     core/                         fizzimpl                     cat                     dog                     tree                     ...many other objects     src/test/java         ...     build/     lib/     ... 

i want compile under src/main/java/com/myapp/api as as com.myapp.impl.core.fizzimpl, such cat, dog, tree etc. not compiled (and excluded).

in ant build (build.xml), configure following main.compile.path:

<path id="src.path">     <fileset dir="src/main/java/com/myapp/api">         <include name="**.*java"/>     </fileset> </path> <path id="lib.main.path">     <fileset dir="lib/main">         <include name="**/*.jar"/>     </fileset> </path> <path id="main.compile.path">     <path refid="src.path" />     <path refid="lib.main.path" />     <fileset dir="src/main/java" includes="com/myapp/impl/core/**/*" /> </path> 

and following main-compile target:

<target name="main-compile">     <javac includeantruntime="false" srcdir="src/main/java/com/myapp/api"             destdir="gen/bin/main" debug="on">         <classpath refid="main.compile.path"/>     </javac> </target> 

when run main-compile, following build exception:

[javac] /home/myuser/eclipse/workspace/myapp/src/main/java/com/myapp/api/fizzloader.java:14: package com.myapp.impl.core not exist [javac] import com.myapp.impl.core.fizzimpl; [javac]  ...(omitting rest of trace available upon request) 

here, fizzloader creating instance of fizzimpl, , need on compile path.

why ant not see com.myapp.impl.core.fizzimpl have selectively added main.compile.path? in advance!

the classpath of javac should refer directories , jar files containing root of compiled class files trees. should not refer java files.

similarly, source directory should refer root of package tree of source files. not directories corresponding packages, inside package tree.

your compile task should like

<target name="main-compile">     <javac includeantruntime="false"             srcdir="src/main/java"            destdir="${gen.bin.main.dir}"             debug="on"            includes="com/myapp/api/**/*.java, com/myapp/impl/core/fizzimpl/**/*.java">         <classpath refid="lib.main.path"/>     </javac> </target> 

Comments