[PJUG Javamail] Packaging Java Applications

Aaron Getz getza1 at gmail.com
Tue Aug 11 20:07:12 EDT 2009


Dan,
  So everything in your build file looks good but this line here looks a
little suspect.

     includes="${classes.dir}/**/*.class,${project.classpath}

  Are you wanting to package up the 3rd party libs in the jar file?  If so
that isn't really going to work for you unless you go with the FatJar option
Kent was mentioning.  What I usually do is something like this

     <mkdir dir="dist"/>
     <copy todir="dist">
          <fileset dir="bin"/>
     </copy>

     That will put just the com/foo/bar directory structure in your dist
directory and then you can just use the dist directory as the basedir for
the jar task.

    So the classpath issue with the 3rd party jars is what seems to me needs
to be addressed.  You can either using the Classpath attribute of the
manifest task or you can make whoever is using your jar file create their
own classpath.  I would suggest that you make them create their own
classpath because you don't want to dictate their deployment structure.

But yeah you are getting really close, that is great.

Aaron

On Tue, Aug 11, 2009 at 4:44 PM, Dan Colish <dan at unencrypted.org> wrote:

> Ok, I'm really close. My current build file will build correctly, but
> now packaging is not quite right. :) I'll get it soon enough. Here's the
> file inline.
>
> --
> --Dan
>
>
> <project name="test4" basedir="." default="jar">
>        <property name="src.dir" value="src/"/>
>        <property name="classes.dir" value="classes/"/>
>        <property name="bin.dir" value="bin/"/>
>
>
>        <path id="project.classpath">
>                <fileset dir="lib" includes="**/*.jar"/>
>        </path>
>
>         <target name="clean">
>                <delete dir="classes/"/>
>                <delete file="MANIFEST.MF"/>
>                <delete file="test4.jar"/>
>        </target>
>
>        <target name="build" depends="clean">
>                <mkdir dir="${classes.dir}"/>
>                <javac srcdir="src" destdir="classes" debug="true"
>                         debuglevel="source,lines,vars">
>                        <classpath refid="project.classpath"/>
>                </javac>
>        </target>
>
>         <target name="jar" description="jars it up" depends="build">
>                <jar destfile="${ant.project.name}.jar" basedir="."
> includes="${classes.dir}/**/*.class,${project.classpath}">
>                  <manifest>
>                        <attribute name="Built-By" value="${user.name}"/>
>                        <attribute name="Main-Class" value="usermenu.Menu"/>
>                  </manifest>
>                </jar>
>        </target>
> </project>
>
>
> On Tue, Aug 11, 2009 at 03:46:58PM -0700, Kent Spaulding wrote:
> > Ah, okay, I misunderstood.
> >
> > One option is Netbeans, which keeps its project files as ant files and
> > they can simply be built via ant, without requiring the tools. ;-)
> >
> > Other than that, I simply put external libs into a <project-dir>/lib
> > directory and then write an ant script that builds the project - testing
> > it from outside eclipse.  One of the ant targets creates a .zip that is
> > the project to be distributed.
> >
> > --Kent
> >
> > On Aug 11, 2009, at 3:33 PM, Dan Colish wrote:
> >
> >> I'm really not that interested in a runable jar, thats pretty easy to
> >> produce within eclipse. I'm trying to properly setup a java project
> >> that
> >> uses external libraries and builds correctly without requiring
> >> eclipse.
> >> My main concern is the directory structure for the project and any
> >> build
> >> files that are required. I have looked at the ant build.xml files, and
> >> I
> >> am working on that currently, but that is really complex.  Even if I
> >> can't do this without eclipse, I am confident there is a proper way to
> >> do this that does not require an couple hours of setup.  I've gotta be
> >> doing something wrong here. The current project is a simple one, but I
> >> would like to understand the correct way to do this for future
> >> projects.
> >>
> >> --
> >> --Dan
> >>
> >>
> >>
> >> On Tue, Aug 11, 2009 at 03:23:09PM -0700, Kent Spaulding wrote:
> >>> Ant is one means - if all you care about is the executable then use
> >>> eclipse's 'Runnable Jar' feature.
> >>>
> >>> For you project, click File|Export.. and in the treeview select as in
> >>> the attached screenshot.  It will allow you choose what to bundle.
> >>>
> >>> If your version of eclipse doesn't do this, there is a plugin called
> >>> FatJar that will (which is where this feature came from)
> >>>
> >>> The resulting jar file is run as:
> >>>
> >>> java -jar myjar.jar <arguments>
> >>>
> >>> --Kent
> >>>
> >>
> >>
> >> _______________________________________________
> >> Web Site - http://www.pjug.org/
> >> Javamail mailing list
> >> Javamail at pjug.org
> >> http://www.pjug.org/mailman/listinfo/javamail
> >
> _______________________________________________
> Web Site - http://www.pjug.org/
> Javamail mailing list
> Javamail at pjug.org
> http://www.pjug.org/mailman/listinfo/javamail
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.pjug.org/pipermail/javamail/attachments/20090811/05f2a29f/attachment.html 


More information about the Javamail mailing list