在Java Applet中设置环境变量

发布于 2024-12-28 09:51:30 字数 750 浏览 5 评论 0原文

我在我的小程序中使用 xuggler api。 xuggler 的 wiki 说我不能在小程序中使用它。但我用3台电脑试过了。如果我可以将 xugglers bin 文件夹添加到系统环境路径变量并创建一个新的环境变量 XUGGLE_HOME,我的小程序就会工作。我将 xugglers 库复制到目标计算机没有问题。我想做的是这样的:

  • 复制 xuggler 文件
  • 设置环境变量
  • 运行小程序
  • 删除 xuggler 文件
  • 删除环境变量

但可能因为我在小程序中执行这些操作,所以环境变量更改在该小程序运行时不会有效。另一个问题是我如何更改环境变量。因为如果我使用 .bat 文件,它有一个限制,会导致路径变量畸形。而其他选择,如 vbscript 和 .reg 文件则不起作用。(vbscript 在某些计算机上拒绝访问,而 .reg 文件看起来可以工作,但不知何故不起作用)

那么有没有办法在运行小程序之前设置环境变量?

谢谢

编辑:实际上我现在尝试了一种不同的方法,效果非常好。现在,我网站上的小程序仅将 xuggle 文件夹和我的主程序 jar 从 zip 文件复制到临时目录中。然后小程序启动 zip 文件中的 bat 文件。 Bat 文件设置(不是 setx)变量并运行我的主 jar。因为子进程获得了父进程的环境,所以它可以工作。 cmd窗口关闭后,系统没有任何变化。除非我可以隐藏那个 cmd 窗口。

嗯,也就是说我仍然想知道是否可以更改java中的环境变量。

I'm using xuggler api in my applet. And xuggler's wiki says I cannot use it in an applet. But I tried it with 3 computers. And my applet will work if I can add xugglers bin folder to system environment path variable and create a new environment variable XUGGLE_HOME. I have no problem with copying xugglers libraries to target computer. What I would like to do is something like that:

  • Copy xuggler files
  • Set environment variables
  • Run applet
  • Delete xuggler files
  • Delete environment variables

But probably because I'm doing these in applet, environment variable changes won't be effective in that applets runtime. And another problem is how I could change environment variables. Because if I use a .bat file, it has a limit that would make malformations in path variable. And other choices like vbscript and .reg file didn't work.(vbscript gives access denied on some computers and .reg file looks like it works but doesn't work somehow)

So is there anyway to set environment variables prior to running applet?

Thanks

EDIT : Actually I tried a different method now which worked like a charm. Now my applet on website only copies xuggle folders and my main program jar into a temp directory from a zip file. Then applet launches a bat file which was in zip file. Bat file sets (not setx) variables and runs my main jar. Because child process gets parents environment it works. And after that cmd window closed, no change to system. Only if I could hide that cmd window.

Well,that said I still wonder if it's possible to change environment variables in java.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一片旧的回忆 2025-01-04 09:51:30

尝试最新的 Xuggler,它现在在 jar 文件中包含本机代码。我不确定它是否适用于小程序。如果是这样,请通过 Xuggler 支持别名告知我们。

Try the latest Xuggler which now includes the native code in the jar file. I'm not sure if it'll work with applets. If it does, please let us know on the Xuggler support alias.

无声无音无过去 2025-01-04 09:51:30

如果只有小程序需要 XUGGLE_HOME 路径,您可以设置在小程序中使用的参数。

<APPLET CODE="your.class" WIDTH=100 HEIGHT=100>
    <PARAM NAME=XUGGLE_HOME VALUE="path">
</APPLET>

You could set params for use in your applet if only the applet needs the XUGGLE_HOME path.

<APPLET CODE="your.class" WIDTH=100 HEIGHT=100>
    <PARAM NAME=XUGGLE_HOME VALUE="path">
</APPLET>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文