JMF-无权从小程序写入文件
我正在使用 jmf 创建一个应用程序,该应用程序将通过 java web start 和 jnlp 文件在用户计算机上启动。我想创建 JFrame 的 jpg 图像,然后使用这些图像制作 Quicktime 电影。当我作为独立应用程序在用户计算机上运行时,所有这些都有效。 问题是,当通过 Web Start 启动它时,我收到一条错误消息,指出我没有从小程序写入文件的权限。我知道这是使用 jmf 注册表工具设置的,但我不希望我的用户必须在他们的计算机上安装 jmf。 我看到 java bugs 网站有一个解决方案。要添加:
com.sun.media.util.Registry.set("secure.allowSaveFileFromApplets", true)
System.setSecurityManager()
第二行实际上创建了一个错误,所以我把它去掉了。当我使用使用 jmf 的类的构造函数中的第一行运行代码时,没有任何反应。 我想知道是否有人对此有任何解决方案(允许 jmf 在不安装 jmf 的情况下从小程序写入文件的方法)或建议使 java bug 站点的解决方案真正起作用。 谢谢。
编辑-小程序和罐子都已签名
编辑-当我说第二行代码有错误时,我的意思是 Eclipse 中出现语法错误,表示括号不能为空。我没想过将代码与 null 一起使用。我现在已经尝试过了,添加该行并没有什么区别。
我不完全清楚为什么我的程序被视为小程序,但代码抛出的错误特别指出:“java.lang.RuntimeException:没有从小程序写入文件的权限。”所以我想我也可以用 java 的名称来称呼我的程序。
I am creating a application using jmf that will be launched on a user's computer with java web start and a jnlp file. I would like to create a jpg image of a JFrame and then use those images to make a quicktime movie. All of this works when I run as a stand alone application at is just on the user's computer.
The problem is that when it is launched through web start I get an error saying that I do not have permissions to write files from applets. I understand that this is something that is set with the jmf registry tool, but I don't want my users to have to install jmf on their machines.
I saw that there was one solution from the java bugs site. It was to add:
com.sun.media.util.Registry.set("secure.allowSaveFileFromApplets", true)
System.setSecurityManager()
The second line of that actually creates an error, so I took it out. Nothing happened when I ran the code with the first line in the constructor of the class that uses jmf.
I was wondering if anybody had any solutions to this (ways to allow jmf to write files from an applet without installing jmf) or suggestions to make the solution from the java bug site actually work.
Thanks.
Edit- The applet and the jars are all signed
Edit- When I said there was an error from the second line of code I meant something like a syntax error from eclipse saying that the parenthesis cannot be empty. I had not thought to use the code with null. I have tried it now though, and adding the line does not make a difference.
I'm not entirely clear about why my program is considered an applet, but the error the code throws specifically says: "java.lang.RuntimeException: No permissions to write files from applets." So I figure I may as well call my program what java its calling it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很确定我已经弄清楚如何完成这项工作。
首先,您需要确保安装 jmf 的跨平台版本。然后,您需要使用命令行在 JMF-2.1.1e\lib 文件夹中使用以下命令来运行 JMFRegistry。
java -cp jmf.jar;mediaplayer.jar;multiplayer.jar JMFRegistry
现在您需要选中复选框以允许写入和捕获。您现在需要打开 JMFCustomizer 来创建您自己的 jar。您将在上次的同一文件夹中运行以下命令。
java -cpcustomizer.jar; jmf.jar;mediaplayer.jar;multiplayer.jar JMFCustomizer
然后,您需要按照以下步骤创建自定义 jar 文件,确保使用此安装附带的 jmf.jar 文件。
就我个人而言,我只是包含了与录制视频有关的所有内容,但是您可以根据需要制作适合您的 jar 来随意使用定制器。
另外,作为额外的预防措施,我在问题中提到的代码以及行中添加了:
JMFSecurityManager.enableSecurityFeatures();
这些被放入调用 jmf 的类的构造函数中。
希望这能帮助其他有类似问题的人。
I'm pretty sure I've figured out how to make this work.
First you need to make sure that you install the cross platform version of jmf. You will then need to use the command line to run the JMFRegistry with the following command in the JMF-2.1.1e\lib folder.
java -cp jmf.jar;mediaplayer.jar;multiplayer.jar JMFRegistry
Now you need to check the boxes to allow for writing and capturing. You will now need to open the JMFCustomizer to create your own jar. You will run the following command in the same folder as last time.
java -cp customizer.jar; jmf.jar;mediaplayer.jar;multiplayer.jar JMFCustomizer
You will then need to follow the steps to create a custom jar file, making sure to use the jmf.jar file that came with this install.
Personally I just included everything that had to do with recording videos, but you can mess around with the customizer as much as you need to make a jar that works for you.
Also as an added precaution I added in the code I mentioned in my question as well as the line:
JMFSecurityManager.enableSecurityFeatures();
These were put in the constructor of the class that calls jmf.
Hopefully this will help someone else having A similar problem.