栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何为Maven创建新的包装类型?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何为Maven创建新的包装类型?

要做到像你描述,创建包装Maven项目 罐子
(如说在这里,因为不会有魔力的定义)。在src / main / resources / meta-INF /
plexus子文件夹中,创建具有以下内容的components.xml(假设您希望包装类型为“ my-custom-type”,如果您将其更改为“
foobar”希望)。

<component-set>  <components>    <component>      <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>      <role-hint>my-custom-type</role-hint>      <implementation>        org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping      </implementation>      <configuration>    <phases>      <!--use the basic jar lifecycle bindings, add additionalexecutions in here if you want anything extra to be run-->     <process-resources>        org.apache.maven.plugins:maven-resources-plugin:resources      </process-resources>      <package>        org.apache.maven.plugins:maven-jar-plugin:jar      </package>      <install>        org.apache.maven.plugins:maven-install-plugin:install      </install>      <deploy>        org.apache.maven.plugins:maven-deploy-plugin:deploy      </deploy>    </phases>      </configuration>    </component>    <component>      <role>org.apache.maven.artifact.handler.ArtifactHandler</role>      <role-hint>my-custom-type</role-hint>      <implementation>        org.apache.maven.artifact.handler.DefaultArtifactHandler      </implementation>      <configuration>        <!--the extension used by Maven in the repository-->        <extension>foobar</extension>        <!--the type used when specifying dependencies etc.-->        <type>my-custom-type</type>        <!--the packaging used when declaring an implementation ofthe packaging-->        <packaging>my-custom-type</packaging>      </configuration>    </component>  </components></component-set>

然后在要具有自定义包装的pom中,在包装元素中声明所需的类型,并确保您已指定插件,以便可以自定义包装。声明 true 会告诉Maven,该插件为Maven提供了打包和/或类型处理程序。

<project xmlns="http://maven.apache.org/POM/4.0.0"          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0        http://maven.apache.org/maven-v4_0_0.xsd">  <modelVersion>4.0.0</modelVersion>  <groupId>name.seller.rich</groupId>  <artifactId>test</artifactId>  <version>0.0.1-SNAPSHOT</version>  <packaging>my-custom-type</packaging>  <build>    <plugins>      <plugin>        <groupId>name.seller.rich.maven.plugins</groupId>        <artifactId>maven-foobar-plugin</artifactId>        <version>0.0.1</version>        <!--declare that this plugin contributes the component extensions-->        <extensions>true</extensions>      </plugin>    </plugins>  </build> </project>

打包项目时,它将是一个扩展名为.jar的jar,但是,当安装/部署该项目时,Maven会将文件以components.xml中指定的扩展名“
.foobar”传送到存储库中。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/437368.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号