If this is answered somewhere else, kindly smack me and point me in the right direction.
I'm brand new to Maven and trying to wrap my head around how to use it with my projects. I've got two top level projects, one a Swing app, the other is a set of Web Services. They both depend on the same in-house jar. What are good ways to set up the poms for this?
If the jar was only used by one of the projects, then it looks like I'd move it down inside and make it a module. But I don't want two (and later more) copies of that jar's source code.
One way it looks like I could do this is to have a master pom for the Swing app that has the Swing app and the library jar as a modules. Then have another master pom for the Web app set up the same way. Would that make sense? Are there better ways?
The directory structure is currently very straightforward:
Development/
----SwingApp/
----WebServices/
----CoreLibrary/
Way too much info and side questions follow:
I've inherited a "build system" (using the term loosely) which is 100% Netbeans autogenerated ant scripts. I started trying to put it into Continuous Integration, TeamCity, which I really like. I've run into serious problems trying to build the WebServices project with it. There are things in the generated ant (build-impl.xml) that cannot be overridden in the CI environment as far as I can tell. Combine this with some serious classpath hell in day to day development and you're starting to see why I want to go to maven.
One of the issues wrapped up in this question is a habit developers on my team all seem to have. Right now the various projects in Netbeans have project references to the "CoreLibrary" project. What this means is that when source is changed in "CoreLibrary" and the developer does a build on a top level app, it will also build the CoreLibrary as necessary. Can that be simulated in Maven? It would go a ways to ease the transition. So far I'm seeing that Netbeans (6.7) doesn't do that with maven builds, and I don't think I can sell (yet) doing the day-to-day build work outside of Netbeans.
Within your Development directory you would have a pom which would look something like the following:
<project>
<groupId>yourGroup</groupId>
<artifactId>project</artifactId>
<packaging>pom</packaging>
<modules>
<module>coreLibrary</module>
<module>swingApp</module>
<module>webServices</module>
</modules>
</project>
yeah, I've left out some of the other elements, so fill in whatever else you need for a complete pom.
Then, your coreLibrary, swingApp, and webServices modules would each have a pom with a parent element, and any dependencies, as follows
<project>
<parent>
<groupId>yourGroup</groupId>
<artifactId>project</artifactId>
<version>yourVersion</version>
</parent>
<artifactId>webServices</artifactId>
<packaging>war</packaging>
<version>yourVersion</version>
<dependencies>
<dependency>
<groupId>yourGroup</groupId>
<artifactId>coreLibrary</artifactId>
<version>yourVersion</version>
</dependency>
</dependencies>
</project>
If you build at the root level, then it will build all 3 modules, or, even better, you could use the --also-make option to build only webServices and its dependencies (in this case coreLibrary)
mvn -am --projects webServices clean install
You shouldn't be adding the .jars into your projects. You should be adding JAR dependencies to your .pom files. Maven will download the .jars for you. You will have to create .pom files for each in-house .jar and add them to your maven repository (or proxy if you have one.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With