I think I understand now.

The documentation for javac says that javac expects source files to live in a 
package tree, but that does not apply to the
source files on the command line.

> On Dec 21, 2023, at 10:07 AM, Alan Snyder <contagiousarrow...@cbfiddle.com> 
> wrote:
> 
> Thank you for the suggestion. It seems to work.
> 
> I do not understand why my previous snippet worked. If java used srcdir=“.” 
> as the root of a package tree,
> then why did it compile files in a and b as top level classes? (The files in 
> a and b did not declare a package.)
> 
>  Alan
> 
> 
>> On Dec 20, 2023, at 10:02 PM, ilya Basin <basini...@gmail.com> wrote:
>> 
>> Alan. I never used srcpath before and after some trial and error I feel that 
>> the source of the problem is bad description of the option in JDK.
>> Ant passes srcpath directly to JDK's javac (unlike srcdir which Ant itself 
>> searches for java files).
>> 
>> The description says "Specify" or "Specifies", but it actually "overrides" 
>> the default. And the default is current dir ".".
>> The other important thing the short description doesn't mention is javac 
>> won't compile all source files in srcpath, but only those needed by 
>> explicitly listed source files.
>> So by default javac will look in the current dir for source files needed to 
>> compile explicitly listed source files.
>> 
>> You probably want all sources in "a" and "b" to be compiled so you shouldn't 
>> use srcpath for them.
>> 
>> Finally, javac does not accept fileset as <src> or srcdir. In your example 
>> "p" was consisting of java files and it was wasn't failing for you because 
>> it was used as srcpath and srcpath was never scanned by javac because all 
>> needed sources were found in srcdir.
>> 
>> Ant docs could be better too. I wasn't able to find examples of <src 
>> refid=.../> on the site.
>> 
>> Please try my variant:
>> 
>>   <?xml version="1.0" encoding="UTF-8"?>
>> 
>>   <project name="test" default="t" basedir=".">
>> 
>>     <path id="p">
>>       <path path="a"/>
>>       <path path="b"/>
>>     </path>
>> 
>>     <target name="t">
>>       <javac>
>>         <src refid="p"/>
>>       </javac>
>>     </target>
>> 
>>   </project>
>> 
>> 
>> 
>> 
>> -------- Original Message --------
>> From: Alan Snyder [mailto:contagiousarrow...@cbfiddle.com]
>> Sent: Wednesday, December 20, 2023 at 23:37 UTC
>> To: Ant Users List
>> Subject: javac task question
>> 
>> 
>> This actually does what I want:
>> 
>> <?xml version="1.0" encoding="UTF-8"?>
>> 
>> <project name="test" default="t" basedir=".">
>> 
>> <path id="p">
>>   <fileset dir="a"/>
>>   <fileset dir="b"/>
>> </path>
>> 
>> <target name="t">
>>   <javac srcdir="." sourcepathref="p"/>
>> </target>
>> 
>> </project>
>> 
>> The problem is that I don’t really want to specify srcdir, but if I leave it 
>> out, the build fails (see below).
>> I would need to create a fake directory to use as srcdir to be sure that I 
>> don’t accidentally compile unwanted sources.
>> 
>> 
>> Apache Ant(TM) version 1.10.14 compiled on August 16 2023
>> Trying the default build file: build.xml
>> Buildfile: /Users/alan/testAnt1/build.xml
>> Detected Java version: 21 in: 
>> /Library/Java/JavaVirtualMachines/jdk-21.0.1.jdk/Contents/Home
>> Detected OS: Mac OS X
>> parsing buildfile /Users/alan/testAnt1/build.xml with URI = 
>> file:/Users/alan/testAnt1/build.xml
>> Project base dir set to: /Users/alan/testAnt1
>> parsing buildfile 
>> jar:file:/Users/alan/.ant/lib/vbuilder-ant-uber-1.0-SNAPSHOT.jar!/org/apache/tools/ant/antlib.xml
>>  with URI = 
>> jar:file:/Users/alan/.ant/lib/vbuilder-ant-uber-1.0-SNAPSHOT.jar!/org/apache/tools/ant/antlib.xml
>>  from a zip file
>> parsing buildfile 
>> jar:file:/usr/local/ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml with 
>> URI = jar:file:/usr/local/ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml 
>> from a zip file
>> Build sequence for target(s) `t' is [t]
>> Complete build sequence is [t, ]
>> 
>> t:
>> 
>> BUILD FAILED
>> /Users/alan/testAnt1/build.xml:11: either srcdir or modulesourcepath 
>> attribute must be set!
>>      at org.apache.tools.ant.taskdefs.Javac.checkParameters(Javac.java:1309)
>>      at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:1080)
>>      at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:299)
>>      at 
>> java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
>>      at java.base/java.lang.reflect.Method.invoke(Method.java:580)
>>      at 
>> org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
>>      at org.apache.tools.ant.Task.perform(Task.java:350)
>>      at org.apache.tools.ant.Target.execute(Target.java:449)
>>      at org.apache.tools.ant.Target.performTasks(Target.java:470)
>>      at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1401)
>>      at org.apache.tools.ant.Project.executeTarget(Project.java:1374)
>>      at 
>> org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
>>      at org.apache.tools.ant.Project.executeTargets(Project.java:1264)
>>      at org.apache.tools.ant.Main.runBuild(Main.java:818)
>>      at org.apache.tools.ant.Main.startAnt(Main.java:223)
>>      at org.apache.tools.ant.launch.Launcher.run(Launcher.java:284)
>>      at org.apache.tools.ant.launch.Launcher.main(Launcher.java:101)
>> 
>> Total time: 0 seconds
>> 
>> 
>> On Dec 19, 2023, at 10:17 PM, Jaikiran Pai <jaiki...@apache.org> wrote:
>> 
>> Hello Alan,
>> 
>> It's hard to say what's going on. Do you have a build file (or a snippet) to 
>> show what issue you are running into?
>> 
>> Which version of Java and Ant is this showing up on?
>> 
>> -Jaikiran
>> 
>> On 18/12/23 1:44 am, Alan Snyder wrote:
>> I know of a couple of ways to run javac on more than one source tree.
>> 
>> One way is to use nested src elements.
>> 
>> Another way is like this:
>> 
>> srcdir="${src}:${src2}”
>> 
>> I would like to generalize this solution to a dynamicly determined list of 
>> source trees.
>> 
>> I thought that I could use srcpath for this purpose, but the task would fail 
>> if srcdir was not specified or it did not identify a valid directory.
>> That restriction defeats my purpose.
>> 
>> Is there a solution?
>> 
>> Is the inability to use srcpath by itself a bug?
>> 
>> Thank you.
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
>> For additional commands, e-mail: user-h...@ant.apache.org
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
>> For additional commands, e-mail: user-h...@ant.apache.org
>> 
>> 
>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
>> For additional commands, e-mail: user-h...@ant.apache.org
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
> For additional commands, e-mail: user-h...@ant.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
For additional commands, e-mail: user-h...@ant.apache.org

Reply via email to