简体   繁体   English

如何在我的JNLP应用程序中修复“缺少代码库,权限和应用程序名称清单属性”?

[英]How do I fix “missing Codebase, Permissions, and Application-Name manifest attribute” in my JNLP app?

With the recent Java updates, many people are having trouble with their Java Web Start apps lacking Codebase , Permissions , and Application-name manifest attributes. 随着最近的Java更新,许多人在使用缺少CodebasePermissionsApplication-name manifest属性的Java Web Start应用程序时遇到了问题。 Although there are resources out there to help you accomplish this, I couldn't find any comprehensive answers to this question, I so I felt a Q-and-A would be good. 虽然有资源可以帮助你实现这一目标,但我找不到任何关于这个问题的全面答案,我觉得Q-and-A会很好。 So, here's the question: 所以,这是问题:

My Java Web Start app displays the following warnings in the console: 我的Java Web Start应用程序在控制台中显示以下警告:

Missing Permissions manifest attribute for: http://www.codebase.com/myApp/dist/myApp.jar
Missing Codebase manifest attribute for: http://www.codebase.com/myApp/dist/myApp.jar
Missing Application-Name manifest attribute for: http://www.codebase.com/myApp/dist/myApp.jar

How do I fix this? 我该如何解决?

(1) First, you need to create a text file with all of the attributes you want to add. (1)首先,您需要创建一个包含要添加的所有属性的文本文件。 My text file looks like this: 我的文本文件如下所示:

Permissions: all-permissions
Codebase: http://www.codebase.com/myApp/dist
Application-Name: My Application

I named it addToManifest.txt . 我把它命名为addToManifest.txt Obviously, you'll need to change the parameters to match your application's needs. 显然,您需要更改参数以满足应用程序的需求。

(2) Next, you need to add this to the main .jar and all of the libraries as well. (2)接下来,您需要将其添加到主.jar和所有库中。 The command to do this is: 执行此操作的命令是:

jar ufm dist\myApp.jar addToManifest.txt

of course dist\\myApp.jar will need to point to whatever your main .jar is. 当然dist\\myApp.jar需要指向你的主要.jar。 You'll also need to do this for all of the libraries as well. 您还需要为所有库执行此操作。

jar ufm dist\lib\jcommon-1.0.16.jar addToManifest.txt
jar ufm dist\lib\jfreechart-1.0.13.jar addToManifest.txt
jar ufm dist\lib\joda-time-2.2.jar addToManifest.txt
...

(Note: on Windows, I wrote a .bat file for this.) (注意:在Windows上,我为此写了一个.bat文件。)

Once you do this, the attributes should be written to the .jar s. 执行此操作后,应将属性写入.jar You can open the .jars in a zip manager (like 7-Zip), extract the MANIFEST.MF file, open it in a text editor, and you should see the attributes listed. 您可以在zip管理器(如7-Zip)中打开.jars,解压缩MANIFEST.MF文件,在文本编辑器中打开它,您应该看到列出的属性。

(3) After adding the attributes, you need to resign your app. (3)添加属性后,您需要重新设置应用程序。 The command to do that is: 执行此操作的命令是:

jarsigner dist\myApp.jar -keystore "C:\myApp\KEYSTORE.ks" alias -storepass password

You'll also need to do this for all of your libraries as well: 您还需要为所有库执行此操作:

jarsigner dist\lib\jcommon-1.0.16.jar -keystore "C:\myApp\KEYSTORE.ks" alias -storepass password
jarsigner dist\lib\jfreechart-1.0.13.jar -keystore "C:\myApp\KEYSTORE.ks" alias -storepass password
jarsigner dist\lib\joda-time-2.2.jar -keystore "C:\myApp\KEYSTORE.ks" alias -storepass password

After that, your attributes should be added and your .jar s should be signed! 之后,应添加您的属性,并且您的.jar应该签名!

NOTE: You only need to sign/deploy your libraries once unless you are changing the library structure. 注意:除非要更改库结构,否则只需要对库进行一次签名/部署。 ie, if you are updating your app but the libraries have already had their manifests altered, signed properly, and deployed, you won't need to resign/deploy the libraries unless you are adding/removing libraries from your app. 也就是说,如果您正在更新您的应用程序,但是库已经更改了清单,正确签名并进行了部署,则除非您从应用程序添加/删除库,否则无需重新签名/部署库。

NOTE #2: The current version of Netbeans will add Codebase and Permissions manifest attributes to your primary .jar only , but not to your libraries. 注意#2:Netbeans的当前版本仅将CodebasePermissions清单属性添加到主.jar ,但不添加到您的库。 If you use Netbeans, you will receive a warning from the jar utility when you try to add a duplicate manifest attribute. 如果使用Netbeans,则在尝试添加重复的清单属性时,将从jar实用程序收到警告。 There is a bug report in the queue to have this fixed https://netbeans.org/bugzilla/show_bug.cgi?id=234231 . 队列中有一个错误报告,以便修复此问题https://netbeans.org/bugzilla/show_bug.cgi?id=234231

EDIT: The latest version of Netbeans (8.0) now adds all three ( Codebase , Permissions , and Application-Name ) to the manifest for you. 编辑:最新版本的Netbeans(8.0)现在将所有三个( CodebasePermissionsApplication-Name )添加到清单中。

Another way could be to handle it in your build script itself. 另一种方法是在构建脚本本身中处理它。

Step 1: Define a target to update 第1步:定义要更新的目标

<target name="updateManifest">
    <manifest file="${file}" mode="update">         
        <attribute name="Trusted-Only" value="true"/>
        <attribute name="Permissions" value="all-permissions"/>
        <attribute name="Codebase" value="*"/>          
    </manifest>
</target> 

Step 2: Call the update target and use the new manifest in jar 第2步:调用更新目标并在jar中使用新的清单

    <ant target="updateManifest">
        <property name="file" location="manifest.use" />
    </ant>

    <jar jarfile="${jar_name}.jar" manifest="manifest.use">
        <fileset dir="${dest}">
            <include name="File1" />                
        </fileset>
    </jar>

If the error message looks like this: 如果错误消息如下所示:

Missing Application-Name manifest attribute for: server root/filename.jar

You can solve it this way: 你可以这样解决:

  1. Start control panel 启动control panel

  2. Choose Java Control Panel 选择Java Control Panel

  3. Select Security tab 选择Security选项卡

  4. At Exception Site list click on Edit Site List button 在“ Exception Site list单击“ Edit Site List按钮

  5. Click on Add button. 单击“ Add按钮。

  6. Type the server root (eg.: https://ibank.cib.hu ), and press OK 键入服务器根目录(例如: https : //ibank.cib.hu ),然后按OK

  7. Restart your browser/application. 重启浏览器/应用程序。

Resource here. 资源在这里。

If you use Netbeans, set those attributes in your file nbproject/project.properties: 如果使用Netbeans,请在文件nbproject / project.properties中设置这些属性:

  • manifest.custom.codebase manifest.custom.codebase
  • manifest.custom.permissions manifest.custom.permissions
  • manifest.application.name.attribute manifest.application.name.attribute

The very last one is supported only by Netbeans >= 8.0 (see here ). 最后一个只受Netbeans支持> = 8.0(见这里 )。 The others should work even in Netbeans 7.2. 其他人甚至应该在Netbeans 7.2中工作。 I set jnlp.mixed.code to trusted_only too but maybe it isn't appropriate in your case. 我也将jnlp.mixed.code设置为trusted_only但可能在你的情况下不合适。 You can modify your file jnlp-impl.xml at your own risk if you can't switch to a more recent version of Netbeans. 如果无法切换到更新版本的Netbeans,您可以自行修改文件jnlp-impl.xml。

atulsm's suggestion is better if you don't use Netbeans. 如果你不使用Netbeans,atulsm的建议会更好。

Sample for adding manifest to jar and signing jars.. manifest添加到jar和签名罐子的示例..

<target name="-post-compile">
        <jar destfile="${build.web.dir}/jars/app.jar" >
            <fileset dir="${build.classes.dir}">
                <include name="com/sample/test/client/**/*.*"/>
                <include name="com/sample/test/share/**/*.*"/>
            </fileset>
            <manifest>
                <attribute name="Author" value="${user.name}"/>
                <attribute name="Permissions" value="all-permissions"/>
                <attribute name="Codebase" value="http://localhost:8080/app/"/>
                <attribute name="Application-Name" value="App"/>
            </manifest>
        </jar>
        <signjar keystore="app.keystore"  storepass="test"  jar="${build.web.dir}/jars/app.jar" alias="tomcat" />


        <copyfiles files="${file.reference.javadatepicker.jar}" todir="${build.web.dir}/jars"/>


        <delete dir="${build.web.dir}/WEB-INF/classes/com/sample/app/client"/>
        <!--keytool -genkey -alias tomcat -keystore app.keystore -keypass test -storepass test -validity 1960-->
        <signjar keystore="app.keystore"  storepass="test"  jar="${build.web.dir}/jars/javadatepicker.jar" alias="tomcat" />

    </target>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM