Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Tools / July 2004

Tip: Looking for answers? Try searching our database.

makefiles for Java projects HOWTO?

Thread view: 
Mark H. Wood - 28 Jun 2004 18:09 GMT
I'm looking for some guidance on designing makefiles for Java
projects.  Yeah, I suppose I should learn to use Ant, but I already
understand make (somewhat :-) and I'd like to start out with something
I know.

The challenge, of course, is that I need to put the classes way down
in edu/iupui/ulib/myproject in order to get a proper .jar --
*everything* I want to work on is at some distance from the top of the
project, where I presume the makefile should be.  (In fact that's
probably the only thing that'll be in the project root other than a
subdirectory.)

Is my thinking all messed up?  How can I organize my makefiles so that
I can just key in e.g. 'make jar' and have something usable?

Signature

Mark H. Wood, Lead System Programmer   mwood@IUPUI.Edu
Open-source executable:  $0.00.  Source:  $0.00  Control:  priceless!

Michael Amling - 29 Jun 2004 04:47 GMT
> I'm looking for some guidance on designing makefiles for Java
> projects.  Yeah, I suppose I should learn to use Ant, but I already
[quoted text clipped - 3 lines]
> The challenge, of course, is that I need to put the classes way down
> in edu/iupui/ulib/myproject in order to get a proper .jar --

  What's the problem? Isn't that where the .class files are already?

> *everything* I want to work on is at some distance from the top of the
> project, where I presume the makefile should be.  (In fact that's
[quoted text clipped - 3 lines]
> Is my thinking all messed up?  How can I organize my makefiles so that
> I can just key in e.g. 'make jar' and have something usable?

--Mike Amling
Mark H. Wood - 29 Jun 2004 16:33 GMT
>> I'm looking for some guidance on designing makefiles for Java
>> projects.  Yeah, I suppose I should learn to use Ant, but I already
[quoted text clipped - 5 lines]
>
>    What's the problem? Isn't that where the .class files are already?

Once I noticed 'javac -d', yes they are.  This means that the
Makefile, which is in '.', is going to fill up with path prefixes to
the point that the logic is obscured.

I could put the Makefile down where the classes are, but then 'jar'
won't see the proper directory structure.

The fundamental problem is that the project wants to be rooted in two
different directories simultaneously.

Signature

Mark H. Wood, Lead System Programmer   mwood@IUPUI.Edu
Open-source executable:  $0.00.  Source:  $0.00  Control:  priceless!

Michael Amling - 30 Jun 2004 03:07 GMT
>>>I'm looking for some guidance on designing makefiles for Java
>>>projects.  Yeah, I suppose I should learn to use Ant, but I already
[quoted text clipped - 9 lines]
> Makefile, which is in '.', is going to fill up with path prefixes to
> the point that the logic is obscured.

 I find that ZipLock can help reduce the clutter.

  jar -cf foobaz.jar `java ZipLock edu.project.Foo`

picks up all the classes that Foo needs. The classes accessed only
through reflection still need to be mentioned explicitly, but I use very
few of those.
  You can also reduce clutter with variables, like
D=edu/school/project

boofaz.jar: $D/Foo.class \
 $D/Baz.class \
 $D/Algebra.class \
 $D/Etc.class \
 $D/Mirror.class
    jar -cf boofaz.jar $D/Mirror.class `java ZipLock
edu.school.project.Baz`

--Mike Amling
Roedy Green - 30 Jun 2004 03:29 GMT
>     jar -cf boofaz.jar $D/Mirror.class `java ZipLock
>edu.school.project.Baz

ZipLock is a name chosen difficult to Google. Do you have a source?

what does that `eee` syntax mean?  Is it something like Windows < ?

Signature

Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

Michael Amling - 30 Jun 2004 17:29 GMT
>>    jar -cf boofaz.jar $D/Mirror.class `java ZipLock
>>edu.school.project.Baz
>
> ZipLock is a name chosen difficult to Google. Do you have a source?

  It's at http://www.bmsi.com/java/.

> what does that `eee` syntax mean?  Is it something like Windows < ?

  On Unix systems, the `xxx` command line argument enclosed in reverse
apostrophes gets replaced by the standard output obtained by running xxx
as a command. I haven't found a good equivalent in Windows. (If I need
this capability on Windows, I use Cygwin.) Here's a working example that
I use all the time:

  grep Schmoo `find * -type f|grep '\.java$'`

runs the command(s)

  find * -type f|grep '\.java$'

which writes a list of all files ending in .java contained in the
current directory and all its subdirectories to standard output. That
list then becomes the second and following command line arguments to the
first grep, making it something like

  grep Schmoo Foo.java com/nospam/Baz.java

and that, of course, lists all the occurrences of "Schmoo" in those
.java files.

--Mike Amling
Robert Klemme - 29 Jun 2004 12:51 GMT
> I'm looking for some guidance on designing makefiles for Java
> projects.  Yeah, I suppose I should learn to use Ant, but I already
> understand make (somewhat :-) and I'd like to start out with something
> I know.

Ant isn't that diffcult and you may very well discover that all the effort
you took to create a Makefile was superfluous.  I'll attach a reasonable
simple ant build file.  Maybe you just give it a try.

> The challenge, of course, is that I need to put the classes way down
> in edu/iupui/ulib/myproject in order to get a proper .jar --
[quoted text clipped - 5 lines]
> Is my thinking all messed up?  How can I organize my makefiles so that
> I can just key in e.g. 'make jar' and have something usable?

I'd follow the usual convention to put sources in <project>/src and
compiled class files into <project>/classes or <project>/bin/classes.  You
javac's command line options "-sourcepath" and "-d" for this.

Kind regards

   robert
Dale King - 03 Jul 2004 21:13 GMT
Hello, Mark H. Wood!
You wrote:

> I'm looking for some guidance on designing makefiles for Java
> projects.  Yeah, I suppose I should learn to use Ant, but I already
> understand make (somewhat :-) and I'd like to start out with something
> I know.

The problem is that make does not work well with java. Javac does
not abide by the rules required bymake:
- Unlike a language like C there can be circular dependencies,
which make does not allow
- Due to those circular dependencies it is not always possible to
compile each java source file searately and you must invoke the
comiler on more than one source file at a time.
- Compiling one source file can actually compile others at the
same time because javac will rebuild other files it sees that are
out of date.

So I don't recommend using make to manage the compilation of java
source.

> The challenge, of course, is that I need to put the classes way down
> in edu/iupui/ulib/myproject

Hey! You're at IUPUI? I am a 2 time alumni of IUPUI and live in
Noblesville. So which school are you in? I can tell you a bit
about 1 or 2 C.S. profs.

> in order to get a proper .jar --
> *everything* I want to work on is at some distance from the top of the
[quoted text clipped - 4 lines]
> Is my thinking all messed up?  How can I organize my makefiles so that
> I can just key in e.g. 'make jar' and have something usable?

I'd really recommend you to use an IDE like Eclipse, which will
handle the details for you. But if you insist on a command line
tool there are a few options:

- If it is a small project with just a few files then it is
usually easier to just create a batchfile that does the work and
simply recompiles everything.
- I do not recommend Ant. Ant is little more than a glorified
batch file. People will tell you that Ant is like make. Make
evaluates dependencies and rebuilds everything that needs to be
built. Ant is vastly inferior to make in this regard. It is easy
to have Ant tell you everything is up to date, when it didn't
build everything.
- I would recommend Maven over Ant. Anything Ant can do maven can
do with a lot less effort.
- The only command line tool that will correctly handle java
compilation dependencies is JavaMake (www.experimentalstuff.com
IIRC). It can be used with Ant or Maven.
Signature

Dale King
My Blog: http://daleking.homedns.org/Blog



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.