File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Ant, Maven and Other Build Tools and the fly likes Subproject .class dependencies Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Subproject .class dependencies" Watch "Subproject .class dependencies" New topic
Author

Subproject .class dependencies

Dave Boden
Ranch Hand

Joined: Nov 08, 2000
Posts: 37
I have the following project layout
|
|- Project A
|
|- Project B
|
|- Project C

Project C has compile time dependencies on the generated class files of Projects A and B.

I've declared the dependencies in the Maven pom.xml files.

When I run the "compile" goal for Project C, it expects to find the .jar files for Project A and Project B in the repository. How do I configure it so that it looks for the .class files in Project A and Project B? Or have I got the wrong end of the stick, do I *need* to create the Project A and Project B jar files first?
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29220
    
135

Dave,
Yes, you need to build projects A and B first. Maven imposes a project structure on you, so you have to do it that way. This makes build files simpler if you can work that way.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Dave Boden
Ranch Hand

Joined: Nov 08, 2000
Posts: 37
Thanks for your reply.

So, if I do an:
m2 compile

on Project C (with dependencies setup to A and B in the pom.xml) then it won't work. Which goal can I use to compile C and force a recursive build of A and B which will result in A and B's jar files being updated in the repository.

Surely this is a very common task? I shouldn't have to run 3 commands to acheive this, Maven 2 should be able to work it all out for me.
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
I'm using maven 1.1 multi project build and i want to build all the sub projects (that have inter-dependencies) at one go. So i added a custom goal on each of the sub projects and the top level project and gave the same name. They in turn do what they need to (creates jars, war and ejb-jars)

Now if I call the newly created top level project goal using multiproject goal, it calls the corresponding goal defined in each of the sub-projects. But what I'm not sure about is the order in which its calling.

Say I have sub projects A,B,C
How does Maven know that that the sequence s'd be A-B-C and not C-A-B or something else? Its working now but I'm not too comfortable.
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
Oh, it just occured to me after posting the question !-
Did Maven infer the subproject build order by reading the project.xml from each of the sub projects and evaluating the specified dependency (on a related subproject)?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Subproject .class dependencies
 
Similar Threads
how to make independent projects ?
ANT : trying not to include jar class files
Eclipse RAD multiple projects
Java commandline -cp parameter
Maven - dependencies of external .jar package