Re: javac task question
Alan Snyder <[email protected]> Fri, 22 Dec 2023 11:36:21 -0800
| Newsgroups | gmane.comp.jakarta.ant.user |
|---|---|
| Message-ID | <[email protected]> |
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=E2=80=AFAM, Alan Snyder = <[email protected]> wrote: >=20 > Thank you for the suggestion. It seems to work. >=20 > I do not understand why my previous snippet worked. If java used = srcdir=3D=E2=80=9C.=E2=80=9D 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.) >=20 > Alan >=20 >=20 >> On Dec 20, 2023, at 10:02=E2=80=AFPM, ilya Basin = <[email protected]> wrote: >>=20 >> 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). >>=20 >> 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. >>=20 >> You probably want all sources in "a" and "b" to be compiled so you = shouldn't use srcpath for them. >>=20 >> 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. >>=20 >> Ant docs could be better too. I wasn't able to find examples of <src = refid=3D.../> on the site. >>=20 >> Please try my variant: >>=20 >> <?xml version=3D"1.0" encoding=3D"UTF-8"?> >>=20 >> <project name=3D"test" default=3D"t" basedir=3D"."> >>=20 >> <path id=3D"p"> >> <path path=3D"a"/> >> <path path=3D"b"/> >> </path> >>=20 >> <target name=3D"t"> >> <javac> >> <src refid=3D"p"/> >> </javac> >> </target> >>=20 >> </project> >>=20 >>=20 >>=20 >>=20 >> -------- Original Message -------- >> From: Alan Snyder [mailto:[email protected]] >> Sent: Wednesday, December 20, 2023 at 23:37 UTC >> To: Ant Users List >> Subject: javac task question >>=20 >>=20 >> This actually does what I want: >>=20 >> <?xml version=3D"1.0" encoding=3D"UTF-8"?> >>=20 >> <project name=3D"test" default=3D"t" basedir=3D"."> >>=20 >> <path id=3D"p"> >> <fileset dir=3D"a"/> >> <fileset dir=3D"b"/> >> </path> >>=20 >> <target name=3D"t"> >> <javac srcdir=3D"." sourcepathref=3D"p"/> >> </target> >>=20 >> </project> >>=20 >> The problem is that I don=E2=80=99t 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=E2=80=99t accidentally compile unwanted sources. >>=20 >>=20 >> 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 =3D = 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/apac= he/tools/ant/antlib.xml with URI =3D = jar:file:/Users/alan/.ant/lib/vbuilder-ant-uber-1.0-SNAPSHOT.jar!/org/apac= he/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 =3D = 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, ] >>=20 >> t: >>=20 >> 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(DirectMet= hodHandleAccessor.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) >>=20 >> Total time: 0 seconds >>=20 >>=20 >> On Dec 19, 2023, at 10:17=E2=80=AFPM, Jaikiran Pai = <[email protected]> wrote: >>=20 >> Hello Alan, >>=20 >> 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? >>=20 >> Which version of Java and Ant is this showing up on? >>=20 >> -Jaikiran >>=20 >> 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. >>=20 >> One way is to use nested src elements. >>=20 >> Another way is like this: >>=20 >> srcdir=3D"${src}:${src2}=E2=80=9D >>=20 >> I would like to generalize this solution to a dynamicly determined = list of source trees. >>=20 >> 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. >>=20 >> Is there a solution? >>=20 >> Is the inability to use srcpath by itself a bug? >>=20 >> Thank you. >>=20 >>=20 >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [email protected] >> For additional commands, e-mail: [email protected] >>=20 >>=20 >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [email protected] >> For additional commands, e-mail: [email protected] >>=20 >>=20 >>=20 >>=20 >>=20 >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [email protected] >> For additional commands, e-mail: [email protected] >>=20 >=20 >=20 > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] >=20