assembly 在Maven中,我如何获得2个具有依赖关系但名称不同的jar副本?

wooyq4lh  于 2022-11-30  发布在  Maven
关注(0)|答案(1)|浏览(145)

我正在处理一个Maven项目,我设置的程序集创建了一个jar,其中包含我需要的所有依赖项,到目前为止,配置构建了2个不同的jar“project-jar-with-dependencies.jar”和“project-plugin.jar”,但我希望构建“project-plugin.jar”的一个副本,该副本末尾不包含“-plugin”。我知道标记“appendAssemblyId”的用法,然而,当我尝试使用它时,我总是得到一个包含比所需内容多得多的jar,即使这是配置标记中的唯一更改。我还尝试使用“finalname”标记,但这个标记似乎没有改变任何东西。
这是我正在使用的pom.xml:

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>"groupId"</groupId>
    <artifactId>"ProjectName"</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>"ProjectName"</name>
    <description>"ProjectName"</description>
    <repositories>
        <repository>
            <id>public</id>
            <name>oXygen public artifacts</name>
            <url>https://www.oxygenxml.com/maven</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        
        
        <repository>
            <id>RepoId</id>
            <name>RepoName</name>
            <url>RepoURL</url>
        </repository>
   
    
    </repositories>
    
    
    <dependencies>
        ...
    </dependencies>
    
    <distributionManagement>
        <repository>
            <id>Repoid</id>
            <name>RepoName</name>
            <url>RepoURL
            </url>
        </repository>
        <snapshotRepository>
            <id>RepoId</id>
            <name>RepoName</name>
            <url>RepoUrl
            </url>
        </snapshotRepository>
    </distributionManagement>
    
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
          <timestamp>${maven.build.timestamp}</timestamp>
         <maven.build.timestamp.format>dd-MM-yyyy HH:mm</maven.build.timestamp.format>
    </properties>
    <build>
        <finalName>${project.artifactId}-${project.version}</finalName>
        <plugins>
            
            <plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.8</version>
                <executions>
                    <execution>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
                            <includeScope>runtime</includeScope>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                 <archive>
        <manifestEntries> <Build-Time>${maven.build.timestamp}</Build-Time></manifestEntries>        
          
        </archive>
                    <outputDirectory>${project.build.directory}/build</outputDirectory>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
<!--Where i ussually add the AppendAssemblyId false -->
                            <archiveBaseDirectory>${project.basedir}</archiveBaseDirectory>
                            <descriptors>
                                <descriptor>assembly.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                </executions>
                <configuration>
        <archive>
        <manifestEntries> <Build-Time>${maven.build.timestamp}</Build-Time></manifestEntries>
         <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>libs/</classpathPrefix>
                            <mainClass>"MainClass".ContentManager</mainClass>
                        </manifest>
          
        </archive>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>    <!--This is an intended extra jar we also need-->
        </descriptorRefs>
      </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.0.2</version>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        
                        <phase>validate</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${basedir}/target/</outputDirectory>
                            <resources>
                                <resource>                              
                                    <directory>${project.basedir}</directory>
                                    <includes>
                                        <include>addon.xml</include>                                        
                                    </includes>
                                    <filtering>true</filtering>
                                </resource>                                                         
                            </resources>                            
                        </configuration>
                    </execution>
                </executions>
            </plugin>

        </plugins>
        
    </build>

</project>

这是Assembly.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>plugin</id>
  <formats>
    <format>jar</format>
  </formats>
  <fileSets>
      <fileSet>
      <directory>target/lib</directory>
      <outputDirectory>lib</outputDirectory>
      <includes>
        <include>**/*</include>
      </includes>
    </fileSet>
  </fileSets>

  <files>
    <file>
      <source>target/build/${project.build.finalName}.jar</source>
      <outputDirectory>/lib</outputDirectory>
    </file>
    <!--This is an attempt at generating a jar without the '-plugin' in the target directory -->
      <file>
          <source>target/build/${project.build.finalName}.jar</source>
          <outputDirectory>${basedir}/target/</outputDirectory>
      </file>
    <file>
      <source>plugin.xml</source>
      <outputDirectory>/</outputDirectory>
      <filtered>true</filtered>
    </file>
  </files>
</assembly>

如前所述,我尝试使用AppendAssemblyId false,但是每当我使用它时,它也会改变jar的内容,我也可能把它放在错误的位置。有没有办法创建一个jar,它是上面提到的jar的完全副本,但是没有“-plugin”在结尾?或者有没有办法从已经创建的jar中取出该字符串?
谢谢

相关问题