add manifest to compiled exe file from jar

2019-08-09 06:52发布

问题:

I've a runnable MyApp.jar which I compiled to MyApp.exe by using launch4j and because this app need administrator permissions I try to add manifest file to it by following this article : http://msdn.microsoft.com/en-us/library/bb756929.aspx When I perform

mt.exe –manifest manifest.xml –outputresource:MyApp.exe;#1

the process completed without errors but MyApp.exe file reduces its size from 6mb to 32kb only and when I try to run it I got the following error: Error: Invalid or corrupt jarfile. Maybe somebody know what's wrong with it? My manifest file is attached below:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> 
  <assemblyIdentity version="1.0.0.0"
     processorArchitecture="X86"
     name="MyApp.exe"
     type="win32"/> 
  <description>{app name}</description> 
  <!-- Identify the application security requirements. -->
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
          level="requireAdministrator"
          uiAccess="true"/>
        </requestedPrivileges>
       </security>
  </trustInfo>
</assembly>

回答1:

Finally we have solved this by adding manifest file through launch4j app during compilation time and changed uiAccess flag from true to false uiAccess="false" despite of the fact that our application is graphic, otherwise it didn't work.

I've used this file:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> 
  <assemblyIdentity version="1.0.0.0"
     processorArchitecture="X86"
     name="MyApp.exe"
     type="win32"/> 
  <description>{app name}</description> 
  <!-- Identify the application security requirements. -->
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
          level="requireAdministrator"
          uiAccess="false"/>
        </requestedPrivileges>
       </security>
  </trustInfo>
</assembly>

And put it here: