【问题标题】:Add an entry to manifest file inside maven-jar-plugin using maven-ant-plugin使用 maven-ant-plugin 向 maven-jar-plugin 内的清单文件添加一个条目
【发布时间】:2018-01-28 03:37:42
【问题描述】:

我正在使用 maven-ant-plugin 设置一个属性,并且我希望将 maven-jar-plugin 中的该属性作为自定义条目放置在 jar 的清单文件中。 我怎样才能做到这一点?

更新:这是我的 pom 文件。我想要属性“abc”的值,它包含要添加到清单文件中的自定义类路径,在 maven-jar-plugin 中。

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>build-folder1-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <prefix>folder1</prefix>
                        <outputDirectory>${project.build.directory}/folder1/</outputDirectory>
                        <outputAbsoluteArtifactFilename>true</outputAbsoluteArtifactFilename>
                        <excludeGroupIds>package.folder1</excludeGroupIds>
                    </configuration>
                </execution>
                <execution>
                    <id>build-folder2-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <prefix>folder2</prefix>
                        <outputDirectory>${project.build.directory}/folder2/</outputDirectory>
                        <outputAbsoluteArtifactFilename>true</outputAbsoluteArtifactFilename>
                        <includeGroupIds>package.folder2</includeGroupIds>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
                <execution>
                    <id>concat-build-classpath</id>
                    <phase>package</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <exportAntProperties>true</exportAntProperties>
                        <target>
                            <path id="master-classpath">
                                <fileset dir="${project.build.directory}/folder1/">
                                    <include name="*.jar" />
                                </fileset>
                                <fileset dir="${project.build.directory}/folder2/">
                                    <include name="*.jar" />
                                </fileset>
                            </path>

                            <property name="absolute-path" value="${toString:master-classpath}" />

                            <loadresource property="relative-path">
                                <propertyresource name="absolute-path" />
                                <filterchain>
                                    <tokenfilter>
                                        <filetokenizer/>
                                        <replaceregex pattern="(^.*?target\\|(?&lt;=;).*?target\\)"
                                            replace="" flags="g" />
                                        <replaceregex pattern="(\\)" replace="/" flags="g" />
                                        <replaceregex pattern="(folder1)"
                                            replace="../folder1" flags="g" />
                                    </tokenfilter>
                                </filterchain>
                            </loadresource>

                            <property name="abc" value="${relative-path}"/>

                        </target>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <executions>
                <execution>
                    <id>include-path-in-jar</id>
                    <phase>install</phase>
                    <configuration>
                        <archive>
                            <manifestEntries>
                                <Class-path>${abc}</Class-path>>
                            </manifestEntries>
                        </archive>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

【问题讨论】:

  • 你为什么要这样做 int maven-ant-plugin 而不是 maven-jar-plugin
  • @Khmarbaise 清单文件的类路径属性列出了项目的所有依赖 jar。我想将一些 jar 名称附加到 folder1/ 和一些附加到 folder2/。我在 maven ant 插件中设置了一个属性,其中包含所需的输出作为其值。我计划在 maven jar 插件的 manifestentries 标记中使用该值。
  • 除此之外,您似乎想创建一个可执行的 jar,这意味着您应该使用 maven-assembly-plugin (jar-with-dependencies) 或者您应该使用 maven-shade-plugin创建这样的东西,它还包含所有依赖项......

标签: maven ant pom.xml


【解决方案1】:

如果你想添加类路径,有一个配置可以这样做:

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    ...
    <configuration>
      <archive>
        <manifest>
          <addClasspath>true</addClasspath>
        </manifest>
      </archive>
    </configuration>
    ...

【讨论】:

  • 我已经试过了。我添加了我的 pom 文件并编辑了我的问题以使其更清晰。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-18
  • 1970-01-01
  • 2017-08-25
  • 2016-08-28
  • 2011-04-26
  • 1970-01-01
相关资源
最近更新 更多