Java小程序找不到JavaPOS配置文件 [英] Java applet can't find JavaPOS configuration files

查看:30
本文介绍了Java小程序找不到JavaPOS配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个小程序,它使用 JavaPOS 与用户本地系统上的支付终端进行通信.

I've created an applet that uses JavaPOS to communicate with a payment terminal on the user's local system.

在 Eclipse IDE 中运行时,小程序运行良好,但在浏览器中运行时则不行.在浏览器中,小程序似乎无法找到 jpos/res/jpos.properties 和 jposxml.cfg 文件.

When run from within the Eclipse IDE, the applet works fine, but not when run in a browser. In a browser, the applet can't seem to find the jpos/res/jpos.properties and jposxml.cfg files.

当在小程序中执行以下语句时(在 start() 方法中,而不是在 init() 中):

When the following statements are executed in the applet (in the start() method, not init()):

JposEntryRegistry registry = JposServiceLoader.getManager().getEntryRegistry();
registry.load();

这是我在 Java 控制台窗口中看到的输出:

this is the output I see in the Java console window:

jpos/res/jpos.properties file not found
jpos/res/jpos.properties file not found
jpos/res/jpos.properties file not found

并且没有条目加载到 JposEntry 注册表中.

And no entries are loaded in the JposEntry registry.

我尝试了以下方法让小程序看到"这两个文件:

I've tried the following to get the applet to "see" the two files:

  1. jpos/res/jpos.properties 已经存在于小程序引用的其中一个 jar 中.不过,我已将此文件添加到小程序的主 jar 中.我还尝试将它添加到包含 jars 的服务器上的目录中(使用正确的相对路径).这些都不行.

  1. jpos/res/jpos.properties is already present in one of the jars referenced by the applet. Nevertheless, I've added this file to the applet's main jar. I've also tried adding it to the directory on the server containing the jars (with the correct relative path). None of this works.

我可以通过使用适当的值设置系统属性来解决无法找到 jpos.properties 的问题,如下所示:

I can work around the inability of jpos.properties to be found by setting System properties with the appropriate values, like this:

System.setProperty("jpos.loader.serviceManagerClass", "jpos.loader.simple.SimpleServiceManager");
System.setProperty("jpos.config.populatorFile", "jposxml.cfg");
System.setProperty("jpos.util.tracing.TurnOnNamedTracers", "JposServiceLoader,SimpleEntryRegistry,SimpleRegPopulator,XercesRegPopulator");
System.setProperty("jpos.util.tracing.TurnOnAllNamedTracers", "ON");

但是,小程序还是找不到jposxml.cfg.该文件位于小程序的主 jar 文件的根目录中.我试过将服务器放在与 jars 相同的目录中.我也尝试创建一个单独的 jar 文件,只包含 jposxml.cfg,但这也不起作用.我在 Java 控制台窗口中得到以下输出:

However, the applet still can't find jposxml.cfg. This file is present in the root of the applet's main jar file. I've tried putting on the server in the same directory as the jars. I've also tried creating a separate jar file containing only jposxml.cfg, but that doesn't work either. I get the following output in the Java console window:

[AbstractRegPopulator]getPopulatorFileIS(): populatorFileName=jposxml.cfg
[JposServiceLoader]manager.getEntryRegistry().load() OK
[AbstractRegPopulator]getPopulatorFileIS(): populatorFileName=jposxml.cfg

但是 JposEntries 的列表是空的.因此,小程序无法与支付终端通信.

But the list of JposEntries is empty. As a result the applet can't communicate with the payment terminal.

小程序通过 JNLP 文件(以及所有必需的 jar 通过 JNLP 扩展)加载.两个 JNLP 文件都将安全设置为 <all-permissions/>.所有 jars 都使用相同的证书签名.相同的代码在 Eclipse 中完美运行.关于问题出在哪里的任何想法?

The applet is loaded via a JNLP file (and all required jars via a JNLP extension). Both JNLP files have security set to <all-permissions/>. All jars are signed with the same certificate. The same code works perfectly in Eclipse. Any ideas on what the problem is?

推荐答案

本文供遇到类似问题的任何人参考.

This is for the reference of anyone facing a similar problem.

我无法获得 JavaPOS 代码来查看 jpos.properties 文件,但是如上所述将值加载到系统属性中是可行的,所以我现在会坚持这样做.

I couldn't get the JavaPOS code to see the jpos.properties file, but loading the values into System properties as described above works, so I'll stick with that for now.

要让 JavaPOS 从 URL 加载 jpos.xml 或 jposxml.cfg,您需要设置属性 jpos.config.populatorFileURL 而不是 jpos.config.populatorFile.这可以在 jpos.properties 中设置,也可以设置为系统属性.

To have JavaPOS load jpos.xml or jposxml.cfg from a URL, you need to set the property jpos.config.populatorFileURL and not jpos.config.populatorFile. This can be set either in jpos.properties, or failing that, as a System property.

这篇关于Java小程序找不到JavaPOS配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆