使用maven-ant-plugin在maven-jar-plugin中的manifest文件中添加一个条目

时间:2018-01-26 09:21:37

标签: maven ant pom.xml

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

更新:这是我的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>

1 个答案:

答案 0 :(得分:0)

如果您想添加类路径,可以使用以下配置:

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