You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "YAWN,MICHAEL (HP-Cupertino,ex1)" <mi...@hp.com> on 2002/03/05 20:18:43 UTC

Completely confused about directories

I'm having no luck navigating through directories in order to build and
package my application.

I want it to be portable (freely downloadable and buildable by users who
may place it in any arbitrary directory), so I'm trying to make all the
directory paths relative.

Here's the structure:

   nfl             - root directory of my hierarchy.   
                     build.xml goes in this directory
      application  - most classes are here
      presentation - UI code is here
      persistence  - JDBC code is here

The build.xml is located at nfl/build.xml.  All classes
are part of nfl package; most are part of one of the 
three subpackages.

Here's the snippet which attempts to compile the classes:

<target name="compile">
  <javac srcdir="." classpath=".." >
    <include name="ObjectFactory.java"/>
    <!-- other files omitted for brevity -->
  </javac>
  <javac srcdir="application" classpathref="classpath">
     <!-- files omitted for brevity -->
  </javac>
  <!-- persistence, presentation subdirs omitted -->
</target>

If I try to compile using this, the ObjectFactory.java compile
fails on the import of nfl.application.*.  I originally tried
with no classpath setting; after failing, I tried creating a
classpath of "..", and then of ".:..".  All fail.  What is
the interaction between the project basedir (set to "."), the
javac srcdir, and the classpath?  What combination must I use
in order for my classes to compile?  (If I continue on into
the subdirectory, any classes that need to be included from
non-local directories also fail, so I'm completely failing
to get javac to recognize a classpath beginning with the
nfl directory)

I have a similar problem trying to jar up the results.  To be
loadable, my classfiles in the .jar file must be saved with the
full package name.  The following code seems to be working:

<target name="jar" depends="compile">
   <jar jarfile="layered.jar" manifest="Manifest" 
        basedir=".." includes="nfl" >
      <zipfileset dir="." prefix="nfl"
                          includes="*.class"
                          excludes="MakeListing.class" />
      <zipfileset dir="application" prefix="nfl/application"
          includes="Conference.class, Division.class,
            Game.class, Games.class, Messaging.class,
            Standings.class, Team*.class, Basic*.class" />
      <zipfileset dir="persistence" prefix="nfl/persistence"
          includes="*Data.class, Basic*.class" />
      <zipfileset dir="presentation" prefix="nfl/presentation" 
          includes="Console.class" />
   </jar>
</target>

But I was a little surprised to have to use the 'zipfileset' 
within the 'jar' target.  Perhaps I'm just too hung up on the
naming mismatch (jar != zip), but is this the expected way to
do this?  

Also, by trying to move the 'base' directory above the package
root, so that classes would be stored with full package-name
prefixes, I caused the scanner to start searching all sorts of
directories that aren't part of my project.  So I had to 
point the scanner to the right place with the includes="nfl"
attribute.  Again, this seems to be working, but I'm feeling
the syntax is awkward and wonder if I've missed an obvious, 
easier way to do this.

Thanks for any pointers that can help me create 'less stupid'
build files.  This is intended for publication, so I really want
to show best practices and not just something that happens to work.

Mike


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Completely confused about directories

Posted by George McKinney <ge...@tantalus.com>.
All (non-absolute) paths in Ant are relative to the basedir - though that
"." MAY refer to your working directory, rather than to the location of the
build file, but I think you'd greatly benefit from a reorganization.

The main change I'd make would be to split the tree like this:

nflroot
   build
      build.xml (basedir="..")
   src
      nfl (source files)
         application (source files)
         presentation (source files)
         persistence (source files)
   classes (classes will be compiled into here - mirroring the src
structure)

For your compile target, you can use
	<javac srcdir="src" destdir="classes" />
to compile the entire src tree into classes. If you want to build different
pieces into different places, split the classes dir into (e.g.) appclasses,
presclasses,... and use several javac tasks with <include> tags to compile
the appropriate files and destdir set to the appropriate output directory.

To run the app, your user will issue java -classpath <appropriate path
prefix>/nflroot/classes nfl.WhateverYourMainClassIs

Assuming you want all the .class files in the .jar, a target depending on
"compile" with:

<jar jarfile="nameOfMyJar.jar" basedir="classes" />
will put everything in with a default manifest. You can add a specific
manifest if you want. If you want specific classes in the .jar, use
includes="..." and excludes="..." or nested <include> <exclude> tags

Things can get MUCH more fancy than this, but I think this may be the
"easier way" you're loking for.

George McKinney, Developer
Tantalus Communications Inc.
500-1122 Mainland Street
Vancouver, BC, Canada V6B 5L1
george@tantalus.com


> -----Original Message-----
> From: YAWN,MICHAEL (HP-Cupertino,ex1) [mailto:mike_yawn@hp.com]
> Sent: Tuesday, March 05, 2002 11:19 AM
> To: 'ant-user@jakarta.apache.org'
> Subject: Completely confused about directories
>
>
> I'm having no luck navigating through directories in order to
> build and
> package my application.
>
> I want it to be portable (freely downloadable and buildable
> by users who
> may place it in any arbitrary directory), so I'm trying to
> make all the
> directory paths relative.
>
> Here's the structure:
>
>    nfl             - root directory of my hierarchy.
>                      build.xml goes in this directory
>       application  - most classes are here
>       presentation - UI code is here
>       persistence  - JDBC code is here
>
> The build.xml is located at nfl/build.xml.  All classes
> are part of nfl package; most are part of one of the
> three subpackages.
>
> Here's the snippet which attempts to compile the classes:
>
> <target name="compile">
>   <javac srcdir="." classpath=".." >
>     <include name="ObjectFactory.java"/>
>     <!-- other files omitted for brevity -->
>   </javac>
>   <javac srcdir="application" classpathref="classpath">
>      <!-- files omitted for brevity -->
>   </javac>
>   <!-- persistence, presentation subdirs omitted -->
> </target>
>
> If I try to compile using this, the ObjectFactory.java compile
> fails on the import of nfl.application.*.  I originally tried
> with no classpath setting; after failing, I tried creating a
> classpath of "..", and then of ".:..".  All fail.  What is
> the interaction between the project basedir (set to "."), the
> javac srcdir, and the classpath?  What combination must I use
> in order for my classes to compile?  (If I continue on into
> the subdirectory, any classes that need to be included from
> non-local directories also fail, so I'm completely failing
> to get javac to recognize a classpath beginning with the
> nfl directory)
>
> I have a similar problem trying to jar up the results.  To be
> loadable, my classfiles in the .jar file must be saved with the
> full package name.  The following code seems to be working:
>
> <target name="jar" depends="compile">
>    <jar jarfile="layered.jar" manifest="Manifest"
>         basedir=".." includes="nfl" >
>       <zipfileset dir="." prefix="nfl"
>                           includes="*.class"
>                           excludes="MakeListing.class" />
>       <zipfileset dir="application" prefix="nfl/application"
>           includes="Conference.class, Division.class,
>             Game.class, Games.class, Messaging.class,
>             Standings.class, Team*.class, Basic*.class" />
>       <zipfileset dir="persistence" prefix="nfl/persistence"
>           includes="*Data.class, Basic*.class" />
>       <zipfileset dir="presentation" prefix="nfl/presentation"
>           includes="Console.class" />
>    </jar>
> </target>
>
> But I was a little surprised to have to use the 'zipfileset'
> within the 'jar' target.  Perhaps I'm just too hung up on the
> naming mismatch (jar != zip), but is this the expected way to
> do this?
>
> Also, by trying to move the 'base' directory above the package
> root, so that classes would be stored with full package-name
> prefixes, I caused the scanner to start searching all sorts of
> directories that aren't part of my project.  So I had to
> point the scanner to the right place with the includes="nfl"
> attribute.  Again, this seems to be working, but I'm feeling
> the syntax is awkward and wonder if I've missed an obvious,
> easier way to do this.
>
> Thanks for any pointers that can help me create 'less stupid'
> build files.  This is intended for publication, so I really want
> to show best practices and not just something that happens to work.
>
> Mike
>
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>