You can do that with the Maven JAR Plugin during the creation of the JAR file. Add the following to your 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>
The main attributes as specified in the JAR File Specification are available as dedicated elements, e.g.:
<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>
See the Maven Archiver Reference for further information.
To modify the manifest inside an existing jar file create a text file, e.g. mymanifest.mf
which contains the required properties:
Trusted-Library: true
You can add the attributes of this file to an existing jar by executing the following command:
jar -cfm file-to-be-modified.jar mymanifest.mf
This will modify the manifest.mf
inside the given jar.