Search code examples
javamavenexecutable-jarlaunch4j

launch4j maven plugin - configure .exe to require administrator role


I'm using launch4j plugin for maven to build .exe file from existing jar. I want to create .exe file which would automatically require administrator role for running it. Is it possible to do it via the plugin? I was unable to find some information if it is actually possible via launch4j maven plugin.

Thanks, Andrey


Solution

  • It appeared that one needs to use manifest file where it's specified that this .exe file built by maven4j plugin should require administrator role to open it. In terms of launch4j plugin it means adding special tag where the path to manifest file should be specified

    So configuration looks like:

    <configuration>
                                <headerType>gui</headerType>
                                <outfile>target/${maser.app.jar.name}64.exe</outfile>
                                <jar>target/${maser.app.jar.name}.jar</jar>    
                               <manifest>src/main/resources/${maser.app.jar.name}64.exe.manifest</manifest>
                                <jre>
                                    <path>bin/${jre64.path}/</path>
                                    <opts>
                                        <opt>-Djava.library.path="dll"</opt>
                                    </opts>
                                </jre>
                                <versionInfo>
                                 ...
                                </versionInfo>
                            </configuration>
    

    and the manifest file looked like:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
        <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
            <security>
                <requestedPrivileges>
                    <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
                </requestedPrivileges>
            </security>
        </trustInfo>
    </assembly>