0

Я пытаюсь создать артефакт Maven, который должен создать исполняемый пакет (в формате JAR), и этот артефакт зависит от другого проекта, который сам зависит от артефакт org.apache.uima.uimafit-core 2.1.0:Как «добавить» к ресурсу, включенному в зависимость от 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/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.stackoverflow.examples</groupId> 
    <artifactId>amend-included-resource</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>${project.artifactId}</name> 

    <properties> 
     <java.version>1.8</java.version> 
     <mainClass>com.stackoverflow.examples.AnalysisEngineTest</mainClass> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 

    <build> 
     <plugins> 
      <plugin> 
       <!-- Adapted from <http://stackoverflow.com/a/574650/1391325> --> 
       <artifactId>maven-assembly-plugin</artifactId> 
       <version>2.6</version> 
       <configuration> 
        <archive> 
         <manifest> 
          <addClasspath>true</addClasspath> 
          <mainClass>${mainClass}</mainClass> 
         </manifest> 
        </archive> 
        <descriptorRefs> 
         <descriptorRef>jar-with-dependencies</descriptorRef> 
        </descriptorRefs> 
       </configuration> 
       <executions> 
        <execution> 
         <id>make-assembly</id> <!-- this is used for inheritance merges --> 
         <phase>package</phase> <!-- bind to the packaging phase --> 
         <goals> 
          <goal>single</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.5.1</version> 
       <configuration> 
        <source>${java.version}</source> 
        <target>${java.version}</target> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 

    <dependencies> 
     <dependency> 
      <groupId>com.stackoverflow.examples</groupId> 
      <artifactId>uimafit-stuff</artifactId> 
      <version>0.0.1-SNAPSHOT</version> 
     </dependency> 
    </dependencies> 
</project> 

зависимость uimafit-stuff определяет a uimaFIT types.txt type description file под main/resources/META-INF/types.txt:

classpath*:desc/type/metadata.xml 

Таким образом, структура проекта выглядит примерно так:

uimafit-stuff 
├── desc 
│ ├── type 
│ │ ├── metadata.xml 
├── META-INF 
│ ├── org.apache.uima.fit 
│ │ ├── types.txt < "classpath*:desc/type/metadata.xml" 

Кроме того, у меня есть свой собственный types.txt файл под amend-included-resource/src/main/resources/META-INF/types.txt:

classpath*:desc/types/MyOwnSpecialType.xml 

Для того, чтобы мой пакет для работы, мне нужно объединение множеств типа дескрипторов, представленных каждым из этих файлов (т.е. Мне нужно добавить мои пути дескриптора типа к включенному файлу или наоборот). Когда я бегу mvn package, файл артефакт без зависимостей содержит только «мой» types.txt:

amend-included-resource-0.0.1-SNAPSHOT.jar 
├── desc 
│ ├── types 
│ │ ├── MyOwnSpecialType.xml 
├── META-INF 
│ ├── org.apache.uima.fit 
│ │ ├── types.txt < "classpath*:desc/types/MyOwnSpecialType.xml" 

Однако JAR создается в процессе сборки с использованием дескриптора jar-with-dependencies содержит types.txt файл из uimafit-stuff и не один из моего проекта:

amend-included-resource-0.0.1-SNAPSHOT-jar-with-dependencies.jar 
├── desc 
│ ├── type 
│ │ ├── metadata.xml 
│ ├── types 
│ │ ├── MyOwnSpecialType.xml 
├── META-INF 
│ ├── org.apache.uima.fit 
│ │ ├── types.txt < "classpath*:desc/type/metadata.xml" 

Как я могу затем убедиться, что обе версии ресурса types.txt каким-то образом «единый», так что я могу запустить мой собранное банку без ошибок во время выполнения?

+0

Сделайте глубокий взгляд в [Maven-тень-плагин] (https://maven.apache.org/plugins/maven-shade-plugin /) имеет большую гибкость в отношении файлов такого рода ... – khmarbaise

ответ

0

Это объясняется в uimaFIT documentation на здании исполняемых JAR.

Здесь соответствующий раздел (под Apache License 2,0)

<build> 
    <plugins> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-shade-plugin</artifactId> 
     <version>2.2</version> 
     <executions> 
     <execution> 
      <phase>package</phase> 
      <goals><goal>shade</goal></goals> 
      <configuration> 
      <transformers> 
       <!-- Set the main class of the executable JAR --> 
       <transformer 
       implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
       <mainClass>org.apache.uima.fit.example.Main</mainClass> 
       </transformer> 
       <!-- Merge the uimaFIT configuration files --> 
       <transformer 
       implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 
       <resource>META-INF/org.apache.uima.fit/fsindexes.txt</resource> 
       </transformer> 
       <transformer 
       implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 
       <resource>META-INF/org.apache.uima.fit/types.txt</resource> 
       </transformer> 
       <transformer 
       implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 
       <resource>META-INF/org.apache.uima.fit/typepriorities.txt</resource> 
       </transformer> 
       <!-- 
       Prevent huge shaded artifacts from being deployed 
       to a Maven repository (remove if not desired) 
       --> 
       <outputFile>${project.build.directory}/${artifactId}-${version}-standalone.jar</outputFile> 
      </transformers> 
      </configuration> 
     </execution> 
     </executions> 
    </plugin> 
    </plugins> 
</build> 

 Смежные вопросы

  • Нет связанных вопросов^_^