Как мы можем скопировать файл в ту же банку сборки с помощью плагина maven

#java #maven

Вопрос:

XML генерируется на этапе компиляции maven, и я хочу включить его в ту же банку (test-one-0.1-SNAPSHOT.jar) файл.

Пример : pom .xml : В этом случае во время компиляции (с использованием моего пользовательского дескриптора) создается один xml-файл «config-all.xml» в целевой папке, которую я хочу включить в ту же банку(test-one-0.1-SNAPSHOT.jar).

 <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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.test</groupId>
  <artifactId>test-one</artifactId>
  <version>0.1-SNAPSHOT</version>
  
  <dependencies>
    <dependency><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-api</artifactId></dependency>
    <dependency><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-core</artifactId></dependency>
    <dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId></dependency>
    <dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId></dependency>
  </dependencies>
  
  <build>
  <plugins>
  <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.3.0</version>
        <executions>
          <execution>
            <phase>compile</phase>
            <goals>
              <goal>single</goal>
            </goals>
            <configuration>
            <archive>
            <manifest>
              <addClasspath>true</addClasspath>
            </manifest>
          </archive>
            <descriptorRefs>
                <descriptorRef>my-custom-descriptor</descriptorRef>
              </descriptorRefs>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>com.test</groupId>
            <artifactId>custom-container-descriptor-handler</artifactId>
            <version>0.0.1-SNAPSHOT</version>
          </dependency>
        </dependencies>
      </plugin>
  </build>
  
</project>

Descriptor file : my-custom-descriptor.xml 

<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
     <id>dist</id> 
    <formats>
        <format>dir</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <dependencySets>
        <dependencySet>
            <outputDirectory>/</outputDirectory>
            <useProjectArtifact>true</useProjectArtifact>
            <useProjectAttachments>true</useProjectAttachments>
            <unpack>true</unpack>
            <scope>runtime</scope>
            <unpackOptions>
                <includes >
                <include>coherence/local/*.xml</include>
                <include>src/main/resources/coherence</include>
                </includes>
                <!-- <excludes>
                <exclude>src/main/resources/coherence/local</exclude>
                </excludes>  -->
            </unpackOptions>
        </dependencySet>
    </dependencySets>
    <containerDescriptorHandlers>
        <containerDescriptorHandler>
            <handlerName>custom</handlerName>
            <!-- <configuration> <comment>A comment</comment> </configuration> -->
        </containerDescriptorHandler>
    </containerDescriptorHandlers>
     <fileSets>
        <fileSet>
            <directory>coherence</directory>
        </fileSet>
    </fileSets> 
</assembly>
 

Комментарии:

1. prepare-package Вместо этого вам следует привязать плагин maven-assembly-к фазе. Также, пожалуйста, покажите дескриптор …лучше всего было бы привести пример проекта… Кроме того, весь проект не может быть собран, потому что отсутствуют версии и т. Д… поэтому приведите полный рабочий пример…

2. Я добавил файл дескриптора : my-custom-descriptor.xml в вышеприведенном