Windows 64 上 Java 的串行端口使用 - 和访问限制?

发布于 2024-11-26 04:15:12 字数 919 浏览 1 评论 0原文

我有一个 Java 程序,可以正确访问 Windows XP 上的串行端口,并且正在尝试让它在我的 Windows 7 (Home Premium) 机器上运行。我正在 Eclipse 中开发。

该程序当前使用 rxtx 类。我的原始下载(适用于 xp)似乎是 32 位特定的,因此我已经获得了 Cloudhopper 64 位实现并将其放入指定的目录中(只要它们与安装说明相匹配),并将 jar 添加为外部jar 到我的项目。

现在,我在使用 rxtx jar 中的类时出现以下错误:

由于限制,无法访问类型 Y 中的字段 X 所需的库 c:\Program Files\Java\jre6\lib\ext\RXTXcomm.jar

我在错误中发现访问限制与 Java 许可协议有关;所有这些类都在 java 包之外,所以我不明白问题是什么。我愿意,但如果我能在不理解问题的情况下解决它,我想我会的。

我发现了几个论坛帖子,都在几年前,声称通过

  1. 从构建路径中删除 JRE 库并重新添加它来解决问题。这对我的情况没有影响。

  2. 消除了 Eclipse 首选项中错误和警告的错误;再次,没有帮助。

我找到了一个商业包,可能可以花费数百美元来完成此操作,但我只是在开发自己的项目,该项目可能永远不会产生任何收入,因此它对我来说不值数百美元为了某种目的而买东西。此外,似乎开源社区中的某些东西是如此接近。

所以我的问题有两个层次:

  1. 有人可以帮助我解决 Eclipse Indigo 中 Java 6 的 Cloudhopper rxtx 实现的访问限制吗?

  2. 是否有另一种使用 Java 访问 Windows 7 上的串行端口的方法,该方法更容易/更好/至少不会出现访问限制问题?

I have a Java program that correctly accessed a serial port on Windows XP, and am trying to get it working on my Windows 7 (Home Premium) box. I am developing in Eclipse.

The program currently uses rxtx classes. My original download (for xp) appears to be 32-bit specific, so I have gotten the Cloudhopper 64-bit implementation and put it in the indicated directories (to the extent that they matched the installation instructions) and added the jar as an external jar to my project.

I now have the following error on any use of classes from the rxtx jar:

The field X from the type Y is not accessible due to a restriction on
the required library c:\Program Files\Java\jre6\lib\ext\RXTXcomm.jar

What I've found on the error is that the access restriction has something to do with the Java licensing agreement; all of these classes are outside the java package so I don't understand what that problem is. I would like to, though if I can solve the problem without understanding it I suppose I will.

I have found several forum posts, none more recent than a couple of years ago, purporting to solve the problem by

  1. eliminating the JRE library from the build path and re-adding it. This had no effect in my case.

  2. eliminating the error in the eclipse preferences for errors and warnings; again, no help.

I have found a commercial package that might be able to do this for hundreds of dollars, but I'm just working on a project of my own that will probably never generate any revenue, and so it isn't worth hundreds of dollars to me to buy something for the purpose. Besides, it seems like something in the open-source community is so close.

So my question has two levels:

  1. Can someone help me with the access restriction on Cloudhopper's rxtx implementation, for Java 6 in eclipse Indigo?

  2. Is there another way to access serial ports on Windows 7 using Java that is easier/better/at-least-doesn't-have-access-restriction-problems?

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

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

发布评论

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

评论(3

青巷忧颜 2024-12-03 04:15:12

我想现在一定是这个非 java 包库位于 JRE 的空间中,尽管我还没有验证这一点。不管怎样,我把它移了出来,然后,在注意到我认为一个项目中的错误是另一个项目中的错误之后,这是由于第二个项目没有将其列为它所需的库这一事实造成的,这帮助了很多。

事实证明,这个和我之前的 32 位版本之间确实存在一些细微的差异——在 eclipse 的帮助下花了 15-30 分钟来解决——但我现在正在读取我的设备!

I think now it must have been the fact that this non-java-package library was in the JRE's space, though I haven't verified that. Anyway, I moved it out and then, after having noticed that the things I thought were errors in one project were errors in a different project, caused by the fact that the second project did not list this as a library it needed, that helped a lot.

There do turn out to be a couple of minor differences between this one and the 32-bit one I had earlier -- took 15-30 minutes to straighten out with eclipse's help -- but I am now reading my device!

一笑百媚生 2024-12-03 04:15:12

根据您的描述,这听起来像是使用 sun.* 包时的标准编译器错误。我在开发一个重用 Sun 的 Base64 类的程序时就遇到过这种情况。

基本上,您正在访问 JRE 的内部结构 - 不需要在版本之间保持一致,并且不适合 Sun/Oracle 之外的开发人员访问。您可以在 Eclipse 中禁用此错误,或者将其降级为警告,但它警告您是有充分理由的。如果您将其更改为警告或在 Eclipse 中忽略它,您仍然可以编译和使用您的程序,但您应该考虑编写自己的提供相同功能的库或寻找第 3 方库。否则,JRE 更新可能会破坏您的程序。

您提到您已经尝试禁用此警告,但没有效果 - 您之后是否执行了干净的构建?尝试 Project->Clean... 并查看是否仍然出现该错误。

From what you've described, this sounds like the standard compiler error when using a sun.* package. I've had it happen to me when working on a program that reused Sun's Base64 classes.

Basically, you're accessing the internals of the JRE -- which are not required to stay consistent between releases, and not meant to be accessed by developers outside of Sun/Oracle. You can disable this error in Eclipse, or downgrade it to a warning, but it's warning you for a good reason. If you change it to a warning or ignore it in Eclipse you can still compile and use your program, but you ought to consider writing your own library that provides the same functionality or looking for a 3rd party lib. Otherwise, a JRE update could break your program.

You mention that you have already tried disabling this warning, and it had no effect -- did you perform a clean build afterwards? Try Project->Clean... and see if you still get that error.

折戟 2024-12-03 04:15:12

解决方案---A

  1. 转到项目属性中的“构建路径”设置。
  2. 删除JRE系统库
  3. 将其添加回来;选择“添加库”并选择JRE系统库。
    默认设置也适用于我的朋友。
    它之所以有效,是因为我们在不同的 jar 文件中有多个类。删除并重新添加 jre 库将使正确的类成为第一个。
    如果您想要一个基本的解决方案,请确保排除具有相同类的 jar 文件。

解决方案---B

  1. 转到项目属性中的“构建路径”设置。 <代码>Windows - >首选项-> Java 编译器
  2. 删除 JRE 系统库
  3. 添加另一个具有“完美匹配”的 JRE
  4. 清理并再次构建您的项目。

Solution---A

  1. Go to the Build Path settings in the project properties.
  2. Remove the JRE System Library
  3. Add it back; Select "Add Library" and select the JRE System Library.
    The default has worked for my friends as well.
    It works because we have multiple classes in different jar files. Removing and re-adding the jre lib will make the right classes be first.
    If you want a fundamental solution make sure you exclude the jar files with the same classes.

Solution---B

  1. Go to the Build Path settings in the project properties. Windows -> Preferences -> Java Compiler
  2. Remove the JRE System Library
  3. Add another JRE with a "perfect match"
  4. Clean and build your project again.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文