You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Ego <m4...@yahoo.it> on 2011/08/20 15:02:08 UTC
Newbie: task can't find my source files
I've read thoroughly the manual and examples but still can't find the reason for this behavior. First, some pointers to state my case.
- Environment: Windows XP SP3, Ant 1.8.1, jdk1.6.0_02
- My project builds and run fine from the cmdline, provided that the CLASSPATH env. variable is set. I can even get a working jar executable from it, so the manifest file (created manually) is also ok. So I tried to repeat the development & deployment process using Ant.
First, I deleted the CLASSPATH env variable to avoid problems. Rebooted my system.
This is my package structure (relative paths):
[root.dir]\ant builfiles\ //contains the xml buildfiles for my projects
[root.dir]\projects\
[root.dir]\projects\modules\
[root.dir]\projects\modules\src\
[root.dir]\projects\modules\src\packages\ // source code for general purpose auxiliary
// classes, w/ subpackages
[root.dir]\projects\modules\src\apps\ // source code for the actual project classes
[root.dir]\projects\modules\src\resources\ // icons and other files required by projects
[root.dir]\projects\WEB-INF\
[root.dir]\projects\WEB-INF\build\ // destdir for the <javac> task
[root.dir]\projects\WEB-INF\dist\ // destdir for the <jar> task
Both the build.xml and build.properties files are located in the "ant buildfiles" folder.
The following is the build.properties file:
src.dir=../projects/modules/src
build.dir=../projects/WEB-INF/build
dist.dir=../projects/WEB-INF/dist
project.name=gdv
main-class=apps.gdv.v1_0_0.GDVLauncher
jar-classpath=.\\gdv.jar // the double backslash is an escape sequence
// and it works fine (more details later)
and this is build.xml file:
<?xml version="1.0"?>
<project name="gdv" default="run">
<property file="build.properties"/>
<target name="clean">
<delete dir="${build.dir}"/>
<delete dir="${dist.dir}"/>
</target>
<target name="init" depends="clean">
<echo>Creating the build directories</echo>
<mkdir dir="${build.dir}"/>
<mkdir dir="${dist.dir}"/>
<!-- this section is an alternate method to include resource files:
<copy todir="${build.dir}/resources">
<fileset dir="${src.dir}/resources"/>
</copy>
Basically is a workaround to get a jar file containing the resource files and a valid manifest despite the whenmanifestonly="skip" property set in the <jar> task. I inspected the resulting manifest file and found it exactly as expected. Manifest and resources are present, the packages with the bytecode obviously not (compilation fails).
-->
</target>
<target name="compile" depends="init">
<javac sourcepath="${src.dir}" srcdir="${src.dir}"
destdir="${build.dir}"
includeantruntime="false"
debug="on"
optimize="on"
fork="true">
<compilerarg value="-Xlint:unchecked"/>
<compilerarg value="-Xlint:deprecated"/>
<compilerarg value="-g"/>
<include name="${src.dir}/packages/sde/actor"/>
<include name="${src.dir}/packages/sde/semaphore"/>
<include name="${src.dir}/packages/sde/monitor"/>
<include name="${src.dir}/packages/synch"/>
<include name="${src.dir}/apps/gdv/v1_0_0"/>
<include name="${src.dir}/resources/gdv/icons"/>
</javac>
</target>
<target name="jar" depends="compile">
<jar destfile="${dist.dir}/${ant.project.name}.jar"
basedir="${build.dir}"
whenmanifestonly="skip"
>
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
<attribute name="Classpath" value="${jar-classpath}"/>
<!-- Who is building this jar? -->
<attribute name="Built-By" value="${user.name}"/>
<!-- Information about the program itself -->
<attribute name="Implementation-Vendor" value="Bogus Inc."/>
<attribute name="Implementation-Title" value="gdv"/>
<attribute name="Implementation-Version" value="1.0.0"/>
<!-- details -->
<attribute name="Sealed" value="false"/>
</manifest>
</jar>
</target>
<target name="run" depends="jar">
<java jar="${dist.dir}/${ant.project.name}.jar" fork="true"/>
</target>
</project>
Finally, here's the verbose output of the ant command:
Apache Ant version 1.8.1 compiled on April 30 2010
Trying the default build file: build.xml
Buildfile: D:\Workspaces\Java\ant buildfiles\build.xml
Detected Java version: 1.6 in: C:\Programmi\Java\jdk1.6.0_02\jre
Detected OS: Windows XP
parsing buildfile D:\Workspaces\Java\ant buildfiles\build.xml with URI = file:/D:/Workspaces/Java/ant%20buildfiles/build.xml
Project base dir set to: D:\Workspaces\Java\ant buildfiles
parsing buildfile jar:file:/C:/apache-ant-1.8.1/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/C:/apache-ant-1.8.1/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
[property] Loading D:\Workspaces\Java\ant buildfiles\build.properties
Build sequence for target(s) `run' is [clean, init, compile, jar, run]
Complete build sequence is [clean, init, compile, jar, run, ]
clean:
[delete] Deleting directory D:\Workspaces\Java\projects\WEB-INF\build
[delete] Deleting directory D:\Workspaces\Java\projects\WEB-INF\build
[delete] Deleting directory D:\Workspaces\Java\projects\WEB-INF\dist
[delete] Deleting directory D:\Workspaces\Java\projects\WEB-INF\dist
init:
[echo] Creating the build directories
[mkdir] Created dir: D:\Workspaces\Java\projects\WEB-INF\build
[mkdir] Created dir: D:\Workspaces\Java\projects\WEB-INF\dist
compile:
[javac] No sources found.
jar:
[jar] Warning: skipping jar archive D:\Workspaces\Java\projects\WEB-INF\dist\gdv.jar because no files were included.
[jar] Warning: skipping jar archive D:\Workspaces\Java\projects\WEB-INF\dist\gdv.jar because no files were included.
run:
[java] Executing 'C:\Programmi\Java\jdk1.6.0_02\jre\bin\java.exe' with arguments:
[java] '-jar'
[java] 'D:\Workspaces\Java\projects\WEB-INF\dist\gdv.jar'
[java]
[java] The ' characters around the executable and arguments are
[java] not part of the command.
[java] Unable to access jarfile D:\Workspaces\Java\projects\WEB-INF\dist\gdv.jar
BUILD SUCCESSFUL
Total time: 5 seconds
I apologize for this long, boring report, I hope you find the time to read it entirely.
Any help will be greatly appreciated, thanks in advance for your patience.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Newbie: task can't find my source files
Posted by Ego <m4...@yahoo.it>.
> You might try to compute the dir and hand that value to
> javac...
>
> For example:
>
> <basename file="${src.dir}"
> property="basedir.basename"/>
> <dirname file="${src.dir}" property="basedir.dir"/>
>
> <javac srcdir="${basedir.dir}/${basedir.basename}"
> .../>
>
>
> Not sure that will fix it...but it may :)
It didn't in fact.
Thanks anyway for all the help.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Newbie: task can't find my source files
Posted by "Scot P. Floess" <sf...@nc.rr.com>.
You might try to compute the dir and hand that value to javac...
For example:
<basename file="${src.dir}" property="basedir.basename"/>
<dirname file="${src.dir}" property="basedir.dir"/>
<javac srcdir="${basedir.dir}/${basedir.basename}" .../>
Not sure that will fix it...but it may :)
On Mon, 22 Aug 2011, Ego wrote:
>> I bet basename will yield src?
>
> Exactly. I typed in the following lines, as suggested:
>
> <basename file="${src.dir}" property="basedir.basename"/>
> <dirname file="${src.dir}" property="basedir.dir"/>
>
> <echo>
> dir = [${basedir.dir}]
> base = [${basedir.basename}]
> </echo>
>
> Side notes:
>
> - versose output contains the line
> Project base dir set to: D:\Workspaces\Java
>
> - source code for project's main class begins with the line:
> package apps.gdv.v1_0_0;
>
> - classes from 'packages' package (yeah, weird naming) begin with:
> package packages.(*);
>
> 'apps', 'packages' and 'resources' are subfolders of ../modules/src (the base dir) hence the package declarations should be ok.
>
> Or maybe there's something I'm missing just here.
>
Scot P. Floess RHCT (Certificate Number 605010084735240)
Chief Architect FlossWare http://sourceforge.net/projects/flossware
http://flossware.sourceforge.net
https://github.com/organizations/FlossWare
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Newbie: task can't find my source files
Posted by Ego <m4...@yahoo.it>.
> I bet basename will yield src?
Exactly. I typed in the following lines, as suggested:
<basename file="${src.dir}" property="basedir.basename"/>
<dirname file="${src.dir}" property="basedir.dir"/>
<echo>
dir = [${basedir.dir}]
base = [${basedir.basename}]
</echo>
Side notes:
- versose output contains the line
Project base dir set to: D:\Workspaces\Java
- source code for project's main class begins with the line:
package apps.gdv.v1_0_0;
- classes from 'packages' package (yeah, weird naming) begin with:
package packages.(*);
'apps', 'packages' and 'resources' are subfolders of ../modules/src (the base dir) hence the package declarations should be ok.
Or maybe there's something I'm missing just here.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Newbie: task can't find my source files
Posted by "Scot P. Floess" <sf...@nc.rr.com>.
I bet basename will yield src?
On Mon, 22 Aug 2011, Ego wrote:
> Good news:
>
> <dirname file="${src.dir}" property="src.dir.name"/>
> <echo message = "Absolute path: ${src.dir.name}"/>
>
> yields:
> D:\Workspaces\Java\projects\modules
>
> instead of the expected:
> D:\Workspaces\Java\projects\modules\src
>
> Surely something's going wrong when processing the includes="" property (or the <include> nested elements, it's the same).
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
Scot P. Floess RHCT (Certificate Number 605010084735240)
Chief Architect FlossWare http://sourceforge.net/projects/flossware
http://flossware.sourceforge.net
https://github.com/organizations/FlossWare
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Newbie: task can't find my source files
Posted by Ego <m4...@yahoo.it>.
Good news:
<dirname file="${src.dir}" property="src.dir.name"/>
<echo message = "Absolute path: ${src.dir.name}"/>
yields:
D:\Workspaces\Java\projects\modules
instead of the expected:
D:\Workspaces\Java\projects\modules\src
Surely something's going wrong when processing the includes="" property (or the <include> nested elements, it's the same).
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Newbie: task can't find my source files
Posted by "Scot P. Floess" <sf...@nc.rr.com>.
D'oh, I should have guessed the src.dir would emit as it did ;)
How about taking the dirname task on src.dir and echoing that?
<dirname file="${src.dir}" property="src.dir.name"/>
<echo message = "Absolute path: ${src.dir.name}"/>
If memory serves, when I kick off my <javac> its usually from a "root"
directory and not a relative one.
On Mon, 22 Aug 2011, Ego wrote:
>
> Woah, thanks Scot! That's a FAST reply, and a good one I think.
> If nothing else, it helped me to rule out some possible causes of error.
>
> To answer your question, I intend to collect my buildfiles in a separate folder, sibling to the projects root, and that's the current dir when I fire "ant". I see your point - I thought myself this could be a potential source of troubles.
>
> Besides, tasks in my buildfile like <copy>, <delete>, <jar> and <mkdir> are interpreting correctly the path specified in ${src.dir}, even when ant is issued from a different location, like I do. Even more strange, <javac> itself points to the same path of the above tasks:
>
> <echo message = "Looking for source files in ${src.dir}"/>
>
> returns
>
> Looking for source files in ../projects/modules/src
>
> Nevertheless the task fails.
> I'm starting to doubt the effectiveness of the <include> selectors or worse, a design bug in the <javac> Ant task when it comes to resolve absolute paths.
>
> Anyway, even placing build.xml in the root dir (editing build.properties accordingly) and setting
>
> project's property
>
> basedir="."
>
> hasn't helped to fix the problem, so there must be some other explanation.
>
> Bye
> Johnny
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
Scot P. Floess RHCT (Certificate Number 605010084735240)
Chief Architect FlossWare http://sourceforge.net/projects/flossware
http://flossware.sourceforge.net
https://github.com/organizations/FlossWare
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Newbie: task can't find my source files
Posted by Ego <m4...@yahoo.it>.
Woah, thanks Scot! That's a FAST reply, and a good one I think.
If nothing else, it helped me to rule out some possible causes of error.
To answer your question, I intend to collect my buildfiles in a separate folder, sibling to the projects root, and that's the current dir when I fire "ant". I see your point - I thought myself this could be a potential source of troubles.
Besides, tasks in my buildfile like <copy>, <delete>, <jar> and <mkdir> are interpreting correctly the path specified in ${src.dir}, even when ant is issued from a different location, like I do. Even more strange, <javac> itself points to the same path of the above tasks:
<echo message = "Looking for source files in ${src.dir}"/>
returns
Looking for source files in ../projects/modules/src
Nevertheless the task fails.
I'm starting to doubt the effectiveness of the <include> selectors or worse, a design bug in the <javac> Ant task when it comes to resolve absolute paths.
Anyway, even placing build.xml in the root dir (editing build.properties accordingly) and setting
project's property
basedir="."
hasn't helped to fix the problem, so there must be some other explanation.
Bye
Johnny
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Newbie: task can't find my source files
Posted by "Scot P. Floess" <sf...@nc.rr.com>.
Took a quick look through your whole email. I'd suggest, putting this in
your compile target:
<target name="compile" depends="init">
<echo message = "*** Attempting to compile src.dir [${src.dir}]"/>
� <javac sourcepath="${src.dir}" srcdir="${src.dir}" ...
...
</target>
Obviously, don't use the ellipses ;) Really all I mean is insert the echo
statement as I've done above... You'll probably see the problem right
away :)
It may be you need to insert the basedir attribute for the <project>
element...
I am curious, what directory are you "standing in" when you kick off your
build? I see that src.dir is a relative directory (meaning
../projects/modules/src)
Personally, I try to not list my directory structures that way. Instead I
prefer to always denote a "root" directory and build everything from that
perspective.
Something like:
project.root = foo
src.dir = ${project.root}/modules/src
Yeah, I know bad example... But you get the idea...
On Sat, 20 Aug 2011, Ego wrote:
> I've read thoroughly the manual and examples but still can't find the reason for this behavior. First, some pointers to state my case.
>
> - Environment: Windows XP SP3, Ant 1.8.1, jdk1.6.0_02
>
> - My project builds and run fine from the cmdline, provided that the CLASSPATH env. variable is set. I can even get a working jar executable from it, so the manifest file (created manually) is also ok. So I tried to repeat the development & deployment process using Ant.
>
> First, I deleted the CLASSPATH env variable to avoid problems. Rebooted my system.
> This is my package structure (relative paths):
>
> [root.dir]\ant builfiles\��� ��� ��� //contains the xml buildfiles for my projects
> [root.dir]\projects\
> [root.dir]\projects\modules\
> [root.dir]\projects\modules\src\
> [root.dir]\projects\modules\src\packages\��� // source code for general purpose auxiliary
> ��� ��� ��� ��� ��� ��� // classes, w/ subpackages
>
> [root.dir]\projects\modules\src\apps\��� ��� // source code for the actual project classes
> [root.dir]\projects\modules\src\resources\��� // icons and other files required by projects
>
> [root.dir]\projects\WEB-INF\
> [root.dir]\projects\WEB-INF\build\��� ��� // destdir for the <javac> task
> [root.dir]\projects\WEB-INF\dist\��� ��� // destdir for the <jar> task
>
>
> Both the build.xml and build.properties files are located in the "ant buildfiles" folder.
> The following is the build.properties file:
>
> src.dir=../projects/modules/src
> build.dir=../projects/WEB-INF/build
> dist.dir=../projects/WEB-INF/dist
> project.name=gdv
> main-class=apps.gdv.v1_0_0.GDVLauncher
> jar-classpath=.\\gdv.jar��� ��� ��� // the double backslash is an escape sequence
> ��� ��� ��� ��� ��� ��� // and it works fine (more details later)
> ��� ��� ��� ��� ��� ���
> and this is build.xml file:
>
> <?xml version="1.0"?>
> <project name="gdv" default="run">
> <property file="build.properties"/>
>
> � � <target name="clean">���
> � � � � <delete dir="${build.dir}"/>
> � � � � <delete dir="${dist.dir}"/>� � � �
> � � </target>
> � �
> � � <target name="init" depends="clean">
> ��� <echo>Creating the build directories</echo>
> ��� <mkdir dir="${build.dir}"/>
> ��� <mkdir dir="${dist.dir}"/>
> ���
> <!-- this section is an alternate method to include resource files:���
> ���
> ��� <copy todir="${build.dir}/resources">
> ��� <fileset dir="${src.dir}/resources"/>
> ��� </copy>
> ���
> Basically is a workaround to get a jar file containing the resource files and a valid manifest despite the whenmanifestonly="skip" property set in the <jar> task. I inspected the resulting manifest file and found it exactly as expected. Manifest and resources are present, the packages with the bytecode obviously not (compilation fails).
>
> -->���
>
> � � </target>
> � �
> � � <target name="compile" depends="init">
> � � � ���<javac sourcepath="${src.dir}" srcdir="${src.dir}"
> � � � � ��� destdir="${build.dir}"
> � � � � ��� includeantruntime="false"
> � � � � ��� debug="on"
> � � � � ��� optimize="on"
> � � � � ��� fork="true">
> � � � � � � ���<compilerarg value="-Xlint:unchecked"/>
> � � � � � � ���<compilerarg value="-Xlint:deprecated"/>
> � � � � � � ���<compilerarg value="-g"/>
> � � � � � � ���<include name="${src.dir}/packages/sde/actor"/>
> � � � � � � ���<include name="${src.dir}/packages/sde/semaphore"/>
> � � � � � � ���<include name="${src.dir}/packages/sde/monitor"/>
> � � � � � � ���<include name="${src.dir}/packages/synch"/>
> � � � � � � ���<include name="${src.dir}/apps/gdv/v1_0_0"/>
> � � � � � � ���<include name="${src.dir}/resources/gdv/icons"/>
> � � � ���</javac>
> � � </target>
>
> � � <target name="jar" depends="compile">
> � � � � <jar destfile="${dist.dir}/${ant.project.name}.jar"
> � � � � � ���basedir="${build.dir}"
> � � � � � ���whenmanifestonly="skip"
> � � � � � ���>
> � � � � � � <manifest>
> ��� ��� <attribute name="Main-Class" value="${main-class}"/>
> ��� ��� <attribute name="Classpath" value="${jar-classpath}"/>
> ��� � � � � <!-- Who is building this jar? -->
> ��� � � � � <attribute name="Built-By" value="${user.name}"/>
> ��� � � � � <!-- Information about the program itself -->
> ��� � � � � <attribute name="Implementation-Vendor" value="Bogus Inc."/>
> ��� � � � � <attribute name="Implementation-Title" value="gdv"/>
> ��� � � � � <attribute name="Implementation-Version" value="1.0.0"/>
> ��� � � � � <!-- details -->
> ��� ��� <attribute name="Sealed" value="false"/>
> � � � � � � </manifest>
> � � � � </jar>
> � � </target>
>
> � � <target name="run" depends="jar">
> � � � � <java jar="${dist.dir}/${ant.project.name}.jar" fork="true"/>
> � � </target>
>
> </project>
>
> Finally, here's the verbose output of the ant command:
>
> Apache Ant version 1.8.1 compiled on April 30 2010
> Trying the default build file: build.xml
> Buildfile: D:\Workspaces\Java\ant buildfiles\build.xml
> Detected Java version: 1.6 in: C:\Programmi\Java\jdk1.6.0_02\jre
> Detected OS: Windows XP
> parsing buildfile D:\Workspaces\Java\ant buildfiles\build.xml with URI = file:/D:/Workspaces/Java/ant%20buildfiles/build.xml
> Project base dir set to: D:\Workspaces\Java\ant buildfiles
> parsing buildfile jar:file:/C:/apache-ant-1.8.1/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/C:/apache-ant-1.8.1/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
> [property] Loading D:\Workspaces\Java\ant buildfiles\build.properties
> Build sequence for target(s) `run' is [clean, init, compile, jar, run]
> Complete build sequence is [clean, init, compile, jar, run, ]
>
> clean:
> ���[delete] Deleting directory D:\Workspaces\Java\projects\WEB-INF\build
> ���[delete] Deleting directory D:\Workspaces\Java\projects\WEB-INF\build
> ���[delete] Deleting directory D:\Workspaces\Java\projects\WEB-INF\dist
> ���[delete] Deleting directory D:\Workspaces\Java\projects\WEB-INF\dist
>
> init:
> � ���[echo] Creating the build directories
> � � [mkdir] Created dir: D:\Workspaces\Java\projects\WEB-INF\build
> � � [mkdir] Created dir: D:\Workspaces\Java\projects\WEB-INF\dist
>
> compile:
> � � [javac] No sources found.
>
> jar:
> � � � [jar] Warning: skipping jar archive D:\Workspaces\Java\projects\WEB-INF\dist\gdv.jar because no files were included.
> � � � [jar] Warning: skipping jar archive D:\Workspaces\Java\projects\WEB-INF\dist\gdv.jar because no files were included.
>
> run:
> � ���[java] Executing 'C:\Programmi\Java\jdk1.6.0_02\jre\bin\java.exe' with arguments:
> � ���[java] '-jar'
> � ���[java] 'D:\Workspaces\Java\projects\WEB-INF\dist\gdv.jar'
> � ���[java]
> � ���[java] The ' characters around the executable and arguments are
> � ���[java] not part of the command.
> � ���[java] Unable to access jarfile D:\Workspaces\Java\projects\WEB-INF\dist\gdv.jar
>
> BUILD SUCCESSFUL
> Total time: 5 seconds
>
> I apologize for this long, boring report, I hope you find the time to read it entirely.
> Any help will be greatly appreciated, thanks in advance for your patience.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
Scot P. Floess RHCT (Certificate Number 605010084735240)
Chief Architect FlossWare http://sourceforge.net/projects/flossware
http://flossware.sourceforge.net
https://github.com/organizations/FlossWare