Java – how to set Maven for two separate projects that depend on the same jar

If you answer this question elsewhere, please blame me and point out the right direction

I am new to Maven and try to use my mind with my project I have two top-level projects, one is swing application and the other is a set of Web services They all depend on the same inner can What is a good way to set up POMS for this?

If the jar is only used by one of the projects, it looks like I'll move it inside and make it a module But I don't want two (and more) copies of the source code of that jar

It seems that one way I can do this is to provide a main POM for swing applications, which contains swing applications and library jars as modules Then set up another main POM for the web application in the same way Does that make sense? Is there a better way?

The directory structure is currently very simple:

Development/  
----SwingApp/  
----WebServices/  
----CoreLibrary/

I inherited a "build system" (in loose terms), which is an ant script automatically generated by 100% NetBeans I started to try to put it into continuous integration, teamcity, which I like very much I had a serious problem trying to build a web services project with it As far as I know, some things in the generated ant (build impl. XML) cannot be overwritten in the CI environment Combine this with some serious classpath hell in daily development, and you'll begin to understand why I'm looking for Maven

One problem with this problem is that the developers on my team seem to be used to it Now, each project in NetBeans has a project reference to the "core library" project This means that when the source code is changed in the "core library" and the developer builds on the top-level application, it will also build the core library as needed Can I simulate in Maven? This will help ease the transition So far, I've seen that NetBeans (6.7) doesn't use Maven version. I don't think I can sell (still) do daily construction outside NetBeans

Solution

In your development directory, you will have a POM similar to the following:

<project>
    <groupId>yourGroup</groupId>
    <artifactId>project</artifactId>
    <packaging>pom</packaging>
    <modules>
        <module>coreLibrary</module>
        <module>swingApp</module>
        <module>webServices</module>
    </modules>
</project>

Yes, I've missed some other elements, so fill in any other elements you need

Then, your core library, swingapp, and WebServices modules will each have a POM with a parent element and any dependencies, as shown below

<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, it will build all three modules, or better yet, you can use the – also make option to build only WebServices and their dependencies (in this case, corelibrary)

mvn -am --projects webServices clean install
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>