如何使用maven配置文件和覆盖来构建和打包指定的项目从多个? [英] How to use maven profile and overlays to build and package with specified project from multiple?

查看:584
本文介绍了如何使用maven配置文件和覆盖来构建和打包指定的项目从多个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为MyWebProject的Web项目,其子模块也包装为POM,我还有其他两个简单的Java项目SimpleJavaProject1和SimpleJavaProject2,其中包装为JAR。



我对网页对象有两个依赖关系。所以我必须使用Maven Profile和Overlays这样的方式,当我将使用配置文件JavaProject1构建和打包我的Web项目时,Web项目在其战争中包含SimpleJavaProject1,当我说JavaProject2时,应该包括SimpleJavaProject2。而且它应该仅用于指定的java项目。



我可以在配置文件中使用叠加层。



请建议一些想法,如果有...

解决方案

得到它...引用@Duncan答案我已经尝试了以下和它的工作。以下是我的个人资料

 <型材> 
< id> JavaProject1< / id>
<属性>
< roject.groupId> mygroupId< /project.groupId>
< roject.artifactId> myartifactId< /project.artifactId>
< roject.version> $ {myversion}< /project.version>
< / properties>
< activate>
< activeByDefault> true< / activeByDefault>
< / activation>
< / profile>

<个人资料>
< id> JavaProject2< / id>
<属性>
< roject.groupId> mygroupId< /project.groupId>
< roject.artifactId> myartifactId< /project.artifactId>
< roject.version> $ {myversion}< /project.version>
< / properties>
< activate>
< activeByDefault> true< / activeByDefault>
< / activation>
< / profile>

我在war plugin中添加了覆盖,如下所示,

 < overlayays> 
< overlay>
< groupId> $ {project.groupId}< / groupId>
< artifactId> $ {project.artifactId}< / artifactId>
< type> jar< / type>
< targetPath> WEB-INF / classes< / targetPath>
< / overlay>
< / overlays>

它工作成功。 : - )


I have one web project called MyWebProject which having sub modules also and packaging as POM, I have other two simple java project called SimpleJavaProject1 and SimpleJavaProject2 which having packaging as JAR.

I am having dependency for both in web peoject. So I have to use Maven Profile and Overlays such way, that when I will build and package my web project with profile JavaProject1 then web project includes SimpleJavaProject1 in its war and when I said JavaProject2 then it should include SimpleJavaProject2. And it should use Overlays only for specified java project.

Can I use Overlays in Profile?

Please suggest some idea if any...

解决方案

Got it...referring @Duncan answer I have tried following and its worked. :-)

Following are my Profiles,

<profile>
    <id>JavaProject1</id>
    <properties>
        <roject.groupId>mygroupId</project.groupId>
        <roject.artifactId>myartifactId</project.artifactId>
        <roject.version>${myversion}</project.version>
    </properties>
    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>
</profile>

<profile>
    <id>JavaProject2</id>
    <properties>
        <roject.groupId>mygroupId</project.groupId>
        <roject.artifactId>myartifactId</project.artifactId>
        <roject.version>${myversion}</project.version>
    </properties>
    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>
</profile>

And I have added Overlays in war plugin as follows,

<overlays>
    <overlay>
        <groupId>${project.groupId}</groupId>
        <artifactId>${project.artifactId}</artifactId>
        <type>jar</type>
        <targetPath>WEB-INF/classes</targetPath>
    </overlay>
</overlays>

It worked successfully. :-)

这篇关于如何使用maven配置文件和覆盖来构建和打包指定的项目从多个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆