plu*_*us- 12 jar maven-3 maven
自上次Java更新以来,我需要使用该Trusted-Library属性标记我的applet jars清单,以避免在javascript与applet通信时出现警告弹出窗口.(见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.)
Run Code Online (Sandbox Code Playgroud)
我之前从未做过这样的事情,是否有一个允许以无缝方式执行此操作的插件,或者我应该编写一个插件,还是使用ant插件?
罐子已经组装好并且可以通过依赖关系获得,复制到目标文件夹中以便在打包期间签名.我正在使用Maven 3
Mat*_*ius 24
您可以在创建JAR文件期间使用Maven JAR插件执行此操作.将以下内容添加到您的pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
<manifestEntries>
<Trusted-Library>true</Trusted-Library>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>sign</id>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
<configuration>
<keystore>/path/to/testkeystore</keystore>
<alias>myalias</alias>
<storepass>test123</storepass>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
JAR文件规范中指定的主要属性可用作专用元素,例如:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
<manifest>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Trusted-Library>true</Trusted-Library>
</manifestEntries>
</archive>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
有关详细信息,请参阅Maven Archiver Reference.
要修改现有jar文件中的清单,请创建一个文本文件,例如mymanifest.mf包含所需属性的文件:
Trusted-Library: true
Run Code Online (Sandbox Code Playgroud)
您可以通过执行以下命令将此文件的属性添加到现有jar:
jar -cfm file-to-be-modified.jar mymanifest.mf
Run Code Online (Sandbox Code Playgroud)
这将修改manifest.mf给定jar 的内部.
最后,我刚刚使用了antrun插件,如下所示,antcontrib用于遍历jar列表:
集结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>
Run Code Online (Sandbox Code Playgroud)
在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>
Run Code Online (Sandbox Code Playgroud)