Alternate locations for javax.comm.properties in Windows

痴心易碎 提交于 2019-12-08 14:31:54

问题


I'm building a program that needs to be installed on Windows machines for which I do not have write access to %JAVA_HOME%/lib.

Is there anywhere else I can move javax.comm.properties to other than %JAVA_HOME%/lib?

According to the Java COM API FAQ:

Q: My application does not find any ports when it enumerates available ports.
A: In order for the Java communications API to find ports the file javax.comm.properties must be in the correct place. The preferred location is in /lib. See the installation instructions for alternate locations and further information.

Where can I find the Sun installation instructions that contain these alternate locations?


回答1:


Base on things that a guy said over here: https://forums.oracle.com/forums/thread.jspa?threadID=1316406

You can put the file javax.comm.properties where you have laid comm.jar. But then to run the program, you should specify the path which points to comm.jar like this:

java -cp <your.class.path>;<path.to>/comm.jar YourProgramThatUsesComm.jar

Hope it helps!




回答2:


I found a way that works for me. Here are the requirements:

  • comm.jar must be named exactly comm.jar (not comm-2.0.jar for example), and must be located in the classpath in a directory named exactly "lib".
  • javax.comm.properties must also have that exact name, and be located in the same directory as comm.jar.
  • win32com.dll must be referenced in the java.library.path.

So, if you have a directory setup like this:

- lib\
   |- comm.jar
   |- javax.comm.properties
- ext\
   |- win32com.dll

Then you can use the following java command while in the root of these directories (assuming your project's jar file with YourMainClass is also in the lib directory:

java -Djava.library.path=.\ext -cp .\lib\* YourMainClass

With this, you should no longer need to put anything under the \bin or \lib directories of your JRE.



来源:https://stackoverflow.com/questions/10819215/alternate-locations-for-javax-comm-properties-in-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!