问题
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 exactlycomm.jar
(notcomm-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 ascomm.jar
.win32com.dll
must be referenced in thejava.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