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

时间:2022-01-10 20:10:06

With the recent Java updates, many people are having trouble with their Java Web Start apps lacking Codebase, Permissions, and Application-name manifest attributes. 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. So, here's the question:

随着最近的Java更新,许多人在使用缺少Codebase,Permissions和Application-name manifest属性的Java Web Start应用程序时遇到了问题。虽然有资源可以帮助你实现这个目标,但我找不到任何关于这个问题的全面答案,我觉得Q-and-A会很好。所以,这是一个问题:

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?

我该如何解决?

5 个解决方案

#1


41  

(1) First, you need to create a text file with all of the attributes you want to add. My text file looks like this:

(1)首先,您需要创建一个包含要添加的所有属性的文本文件。我的文本文件如下所示:

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

I named it addToManifest.txt. Obviously, you'll need to change the parameters to match your application's needs.

我把它命名为addToManifest.txt。显然,您需要更改参数以满足应用程序的需要。

(2) Next, you need to add this to the main .jar and all of the libraries as well. The command to do this is:

(2)接下来,您需要将它添加到主.jar和所有库中。执行此操作的命令是:

jar ufm dist\myApp.jar addToManifest.txt

of course dist\myApp.jar will need to point to whatever your main .jar is. You'll also need to do this for all of the libraries as well.

当然dist \ myApp.jar需要指向你的主要.jar。您还需要为所有库执行此操作。

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 .jars. 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.

执行此操作后,应将属性写入.jars。您可以在zip管理器(如7-Zip)中打开.jars,解压缩MANIFEST.MF文件,在文本编辑器中打开它,您应该看到列出的属性。

(3) After adding the attributes, you need to resign your app. The command to do that is:

(3)添加属性后,您需要重新设置应用程序。执行此操作的命令是:

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 .jars should be signed!

之后,应添加您的属性并签署您的.jars!

NOTE: You only need to sign/deploy your libraries once unless you are changing the library structure. i.e., 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. If you use Netbeans, you will receive a warning from the jar utility when you try to add a duplicate manifest attribute. There is a bug report in the queue to have this fixed https://netbeans.org/bugzilla/show_bug.cgi?id=234231.

注意#2:Netbeans的当前版本仅将Codebase和Permissions清单属性添加到主.jar,但不添加到您的库。如果使用Netbeans,则在尝试添加重复的清单属性时,将从jar实用程序收到警告。队列中有一个错误报告,以便修复此问题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)现在将所有三个(代码库,权限和应用程序名称)添加到清单中。

#2


9  

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>

#3


3  

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

    启动控制面板

  2. Choose Java Control Panel

    选择Java控制面板

  3. Select Security tab

    选择安全选项卡

  4. At Exception Site list click on Edit Site List button

    在“例外站点”列表中,单击“编辑站点列表”按钮

  5. Click on Add button.

    单击“添加”按钮。

  6. Type the server root (eg.:https://ibank.cib.hu), and press OK

    键入服务器根目录(例如:http://www.ibank.cib.hu),然后按确定

  7. Restart your browser/application.

    重启浏览器/应用程序。

Resource here.

#4


2  

If you use Netbeans, set those attributes in your file nbproject/project.properties:

如果使用Netbeans,请在文件nbproject / project.properties中设置这些属性:

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

The very last one is supported only by Netbeans >= 8.0 (see here). The others should work even in Netbeans 7.2. I set jnlp.mixed.code to trusted_only too but maybe it isn't appropriate in your case. 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支持> = 8.0(见这里)。其他人甚至应该在Netbeans 7.2中工作。我也将jnlp.mixed.code设置为trusted_only,但在你的情况下可能不合适。如果无法切换到更新版本的Netbeans,您可以自行修改文件jnlp-impl.xml。

atulsm's suggestion is better if you don't use Netbeans.

如果你不使用Netbeans,atulsm的建议会更好。

#5


2  

Sample for adding manifest to jar and signing jars..

将清单添加到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>

#1


41  

(1) First, you need to create a text file with all of the attributes you want to add. My text file looks like this:

(1)首先,您需要创建一个包含要添加的所有属性的文本文件。我的文本文件如下所示:

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

I named it addToManifest.txt. Obviously, you'll need to change the parameters to match your application's needs.

我把它命名为addToManifest.txt。显然,您需要更改参数以满足应用程序的需要。

(2) Next, you need to add this to the main .jar and all of the libraries as well. The command to do this is:

(2)接下来,您需要将它添加到主.jar和所有库中。执行此操作的命令是:

jar ufm dist\myApp.jar addToManifest.txt

of course dist\myApp.jar will need to point to whatever your main .jar is. You'll also need to do this for all of the libraries as well.

当然dist \ myApp.jar需要指向你的主要.jar。您还需要为所有库执行此操作。

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 .jars. 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.

执行此操作后,应将属性写入.jars。您可以在zip管理器(如7-Zip)中打开.jars,解压缩MANIFEST.MF文件,在文本编辑器中打开它,您应该看到列出的属性。

(3) After adding the attributes, you need to resign your app. The command to do that is:

(3)添加属性后,您需要重新设置应用程序。执行此操作的命令是:

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 .jars should be signed!

之后,应添加您的属性并签署您的.jars!

NOTE: You only need to sign/deploy your libraries once unless you are changing the library structure. i.e., 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. If you use Netbeans, you will receive a warning from the jar utility when you try to add a duplicate manifest attribute. There is a bug report in the queue to have this fixed https://netbeans.org/bugzilla/show_bug.cgi?id=234231.

注意#2:Netbeans的当前版本仅将Codebase和Permissions清单属性添加到主.jar,但不添加到您的库。如果使用Netbeans,则在尝试添加重复的清单属性时,将从jar实用程序收到警告。队列中有一个错误报告,以便修复此问题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)现在将所有三个(代码库,权限和应用程序名称)添加到清单中。

#2


9  

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>

#3


3  

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

    启动控制面板

  2. Choose Java Control Panel

    选择Java控制面板

  3. Select Security tab

    选择安全选项卡

  4. At Exception Site list click on Edit Site List button

    在“例外站点”列表中,单击“编辑站点列表”按钮

  5. Click on Add button.

    单击“添加”按钮。

  6. Type the server root (eg.:https://ibank.cib.hu), and press OK

    键入服务器根目录(例如:http://www.ibank.cib.hu),然后按确定

  7. Restart your browser/application.

    重启浏览器/应用程序。

Resource here.

#4


2  

If you use Netbeans, set those attributes in your file nbproject/project.properties:

如果使用Netbeans,请在文件nbproject / project.properties中设置这些属性:

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

The very last one is supported only by Netbeans >= 8.0 (see here). The others should work even in Netbeans 7.2. I set jnlp.mixed.code to trusted_only too but maybe it isn't appropriate in your case. 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支持> = 8.0(见这里)。其他人甚至应该在Netbeans 7.2中工作。我也将jnlp.mixed.code设置为trusted_only,但在你的情况下可能不合适。如果无法切换到更新版本的Netbeans,您可以自行修改文件jnlp-impl.xml。

atulsm's suggestion is better if you don't use Netbeans.

如果你不使用Netbeans,atulsm的建议会更好。

#5


2  

Sample for adding manifest to jar and signing jars..

将清单添加到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>