Alternate locations for javax.comm.properties in Windows

3.8k views Asked by At

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?

2

There are 2 answers

1
jaselg On

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!

0
dugsmith On

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.