首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用maven-ant-plugin将条目添加到maven-jar-plugin内的清单文件中

使用maven-ant-plugin将条目添加到maven-jar-plugin内的清单文件中
EN

Stack Overflow用户
提问于 2018-01-26 17:21:37
回答 1查看 403关注 0票数 0

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

更新:这是我的pom文件。我希望在maven-jar-plugin中将包含自定义类路径的属性"abc“的值添加到清单文件中。

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

发布于 2018-01-28 00:24:45

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

代码语言:javascript
复制
 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    ...
    <configuration>
      <archive>
        <manifest>
          <addClasspath>true</addClasspath>
        </manifest>
      </archive>
    </configuration>
    ...
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48458543

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档