add permissions attribute in manifest third party jars using maven
Asked Answered
C

1

10

How can we add additional parameters to manifest file using Maven to third party jars. After Java 7_25 version the Java web start requires codebase and permissions to be add in all downloading jar files. I want to insert them jar singing time.

Please let me know if you need any information. Thanks in advance.

Cai answered 20/9, 2013 at 22:25 Comment(3)
May an über-JAR be of use to you?Weigle
@SanderVerhagen uberjar has its pitfall. If two or more jars contain resources with exact same path then its hard to determine which will be loaded. I had a problem with Spring jars. A lot of spring jars contain META-INF/spring.* files which overlaps each otherBluenose
Not a rhetorical question: how is that different than having these files on the classpath at the same time?Weigle
B
4

i made a little ant script (this is an extract, in fact it also excludes some crypto file).

just set directory property value to a directory that contains jars to be updated and launch the target "give-permissions".

it should be easy to use with maven-ant:

<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." name="project">
    <taskdef resource="net/sf/antcontrib/antcontrib.properties" />

    <property name="directory" value="WebContent/jnlpApplication" />

    <target name="give-permissions">
        <foreach target="_re-jar" param="currentFile" parallel="false">
            <path>
                <fileset dir="${directory}" casesensitive="yes">
                    <include name="**/*.jar" />
                </fileset>
            </path>
        </foreach>

        <move todir="${directory}" overwrite="true">
            <fileset dir="${directory}.tmp" casesensitive="yes">
                <include name="**/*.jar" />
            </fileset>
        </move>

        <delete dir="${directory}.tmp" />
    </target>

    <target name="_re-jar">
        <basename property="filename" file="${currentFile}" />

        <jar destfile="${directory}.tmp/${filename}">
            <zipfileset src="${currentFile}">
                <exclude name="META-INF/**.RSA" />
                <exclude name="META-INF/**.SF" />
            </zipfileset>
            <manifest>
                <attribute name="Permissions" value="all-permissions" />
                <attribute name="Codebase" value="*" />
                <attribute name="Application-Name" value="jnlpApplicationName" />
            </manifest>
        </jar>
    </target>
</project>
Bakke answered 31/10, 2013 at 1:35 Comment(3)
thanks for giving answer, I got it. Now it is working fine for me.Cai
great script, one minor thing: I had to add the classpath of the ant-contrib: <taskdef resource="net/sf/antcontrib/antcontrib.properties"> <classpath> <pathelement location="e:\\ant-contrib\\ant-contrib-1.0b3.jar"/> </classpath> </taskdef>Latinist
If you put ant-contrib-1.0b3.jar in your ant/lib directory, along with its dependencies (comes with the zip), then you don't need the <classpath> reference in your build.xml file. ant-contrib.sourceforge.net.Alee

© 2022 - 2024 — McMap. All rights reserved.