繁体   English   中英

作为Maven工件,我可以拥有什么?如何使用它?

[英]What can I have as a Maven artifact and how can I use it?

我知道这似乎已经是一个问题,但是我没有找到一个对我有很大帮助的答案。

我读过很多次,最好每个项目都生成一个工件。 但是我的问题是:作为Maven工件我可以拥有什么?

例如:我有一个带有自定义生命周期的自定义包装“ MyPack”,是否可以将整个目录“ Mydirectory”作为人工制品?

假设目录的结构如下:

我的目录
----- |-罐子
----- | ----- | --- client.jar
----- | ----- | --- server.jar
----- | --jsps
----- | ----- | --- page1.jsp
----- | ----- | --- page2.jsp
----- | --imgs
----- | ----- | --- img1.png
----- | ----- || --- img2.png

然后,我要创建一个新项目,该项目具有包装“ MyPack”和类型为“ MyPack”的依赖项。 在这个项目中,我的Java类需要Maven存储库中的client.jar和server.jar进行编译,并且我想从新项目中的存储库中复制所有jsps和img。

我可以使用自定义Maven插件来完成所有这些工作吗?

无论您选择拥有什么作为工件,都可以拥有Maven工件。 使用maven程序集插件生成工件:

    <build>
       <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <descriptors>
                    <descriptor>${basedir}/src/main/assembly/shared.xml</descriptor>
                </descriptors>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
     ....
      </plugins> 
     ....
  </build>      

在shared.xml文件中,您指定要包含在工件中的格式和文件:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>shared</id>
<formats>
    <format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
    <fileSet>
        <outputDirectory>/</outputDirectory>                            
        <directory>${basedir}/.....</directory>
        <includes>
            <include> ... </include>
        </includes>
        <fileMode>0644</fileMode>
        <filtered>false</filtered>
        <lineEnding>unix</lineEnding>
    </fileSet>
  </fileSets>
</assembly>

当您进行“ Maven部署”时,“共享的”工件将与项目的主要工件一起打包和部署。 为了在另一个项目中使用工件,请使用目标为“ unpack-dependencies”的maven-dependency-plugin

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM