将属性添加到 Maven 中的 jar 清单的最简单方法 [英] Simpliest way to add an attribute to a jar Manifest in Maven

查看:33
本文介绍了将属性添加到 Maven 中的 jar 清单的最简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自上次 Java 更新以来,我需要使用 Trusted-Library 属性标记我的小程序 jar 清单,以避免在 javascript 与小程序通信时弹出警告.(参见 http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/mixed_code.html)

Since the last Java update, I need to tag my applet jars manifest with the Trusted-Library attribute to avoid warning popup when javascript is communicating with the applet. (see http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/mixed_code.html)

Manifest-Version: 1.0
Trusted-Library: true
Created-By: 1.6.0-internal (Sun Microsystems Inc.)

我以前从来没有做过这样的事情,有没有插件可以无缝地做到这一点,还是我应该写一个,或者使用 ant 插件?

I never done such things before, is there a plugin which allow to do that in a seamless way or should I write one, or use the ant plugin?

jar 已经组装好并通过依赖项可用,复制到目标文件夹中以在打包期间签名.我正在使用 Maven 3

The jars are already assembled and available through dependencies, copied in the target folder to be signed during the packaging. I'm using Maven 3

推荐答案

最后我只用了 antrun 插件如下,antcontrib 用于循环遍历 jars 列表:

In the end I just used the antrun plugin like the following, antcontrib is used to loop over the list of jars:

build-trusted.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- This is a wrapper for all the other build files. -->
<project basedir="." name="project_name">

  <target name="addTrustedLibraryProperty">
    <jar file="${jarFile}" update="true">
      <manifest>
        <attribute name="Trusted-Library" value="true" />
      </manifest>
    </jar>
  </target>

  <target name="addTrustedLibraries">
    <ac:foreach target="addTrustedLibraryProperty" param="jarFile" xmlns:ac="antlib:net.sf.antcontrib">
      <path>
        <fileset dir="target/lib" includes="**/*.jar" />
      </path>
    </ac:foreach>
  </target>

</project>

在 pom 中

<plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <id>add-trusted-library-attribute</id>
            <phase>package</phase>
            <configuration>
              <target>
                <ant antfile="${basedir}/build-trusted.xml">
                  <target name="addTrustedLibraries" />
                </ant>
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>ant-contrib</groupId>
            <artifactId>ant-contrib</artifactId>
            <version>1.0b3</version>
            <exclusions>
              <exclusion>
                <groupId>ant</groupId>
                <artifactId>ant</artifactId>
              </exclusion>
            </exclusions>
          </dependency>
          <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant-nodeps</artifactId>
            <version>1.8.1</version>
          </dependency>
        </dependencies>
      </plugin>

这篇关于将属性添加到 Maven 中的 jar 清单的最简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆