Javac is a compiler; getting it to move files around is using the wrong tool for the job.
I would suggest simply using an Ant copy task directly before or after the <javac>
task to move existing class files across. Something like:
<copy todir="${temp}">
<fileset dir="${src}">
<include name="**/*.class" />
</fileset>
</copy>
EDIT for Eclipse: what you're really trying to do here isn't have Eclipse copy the files, but for it to recognise that there are classes there that it needs to reference. So the simplest approach and one that I'd try first is to mark your src
directory as a location that contains classes as well as one that contains sources.
I don't know if this would work for Eclipse - IDEA for example doesn't let a folder act as dual-purpose in this way. And again, it doesn't seem like it's quite the right tool for the job, as an IDE build is just collating the binaries it needs to run the app, and copying files around based on some project settings seems wrong somehow.
Ultimately I don't think your design is the cleanest, mixing classes in with source files is likely to be confusing. I appreciate that you're doing this because you want to use relative references, but perhaps you ought to abstract this out from the filesystem itself and use Classloader.findResource() (or probably getResourceAsStream()
). This way you could arrange the files however you want, and so long as you run your application with both directories on the classpath, Java will be able to find the resource you're after. This will give you more flexibility in general, as well as solving this particular situation.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…