1 2 Previous Next 15 Replies Latest reply on Sep 8, 2010 7:46 AM by 843804

    can't find javax.comm.properties

      I'm trying to set up the Java Communications API on Linux, and I can't seem to get it to find my javax.comm.properties file. I've put comm.jar in $JDK_HOME/jre/lib/ext and the properties file in $JDK_HOME/jre/lib and $JDK_HOME/lib (using JDK 1.4.2_08).

      I set my CLASSPATH to "$JDK_HOME/jre/lib/ext/comm.jar:BlackBox.jar" and when I try to run BlackBox, I get:
      javax.comm: Error loading javax.comm.properties!

      java.io.IOException: javax.comm: platform driver class name = null
      (Check 'driver' property in javax.comm.properties)

      at javax.comm.CommPortIdentifier.loadDriver(CommPortIdentifier.java:244)
      at javax.comm.CommPortIdentifier.<clinit>(CommPortIdentifier.java:109)
      at BlackBox.main(Unknown Source)
      Exception in thread "main" java.lang.UnsatisfiedLinkError: isSessionActive
      at com.sun.comm.SunrayInfo.isSessionActive(Native Method)
      at com.sun.comm.Portmapping.registerCommPorts(Portmapping.java:155)
      at com.sun.comm.Portmapping.refreshPortDatabase(Portmapping.java:100)
      at javax.comm.CommPortIdentifier.<clinit>(CommPortIdentifier.java:138)
      at BlackBox.main(Unknown Source)

      Any idea what's wrong?
        • 1. Re: can't find javax.comm.properties

          I have exactly the same problem on SuSE Linux 9.1 with JDK 1.4.2_08 and JRE 1.5.0_04. I tried also to put comm.jar explicitly into CLASSPATH. javax.comm.properties is in the lib-directory and world-readable. It is unchanged and contains the wanted line.

          What's going on there?!?

          Best regards,
          • 2. Copy javax.comm.properties to working directory

            I got it working now (at least it gives no errors and finds the ports) by copying the javax.comm.properties to the working directory. No idea whether this is intentional...

            Best regards,
            • 3. Re: can't find javax.comm.properties
              This approach worked for me:
              - put driver (*.so or *.dll) in $JAVA_HOME/jre/lib/i386
              - put comm.jar in $JAVA_HOME/jre/lib/ext
              - put javax.comm.properties in a JAR file in the classpath -- in my case, I put it inside the applet JAR.
              - sign the applet, of course

              The real magic seemed to be the javax.comm.properties -- contrary to what it says in the comments in that file, I don't see it being loaded just by virtue of plopping it in jre/lib or jre/lib/ext. However, it did seem to work from the command line when I put it explicitly in my classpath; didn't do me much good with an applet, though.

              There are several other deployment options: comm.jar can be downloaded with the applet instead of in jre/lib/ext, in which case it needs to be signed too. Also, you could in theory download the *.so/*.dll with the applet too, dump it in a temp directory and load it explicitly with System.load(path), which would obviate the need to install stuff on the client side.
              • 4. Re: can't find javax.comm.properties
                Ok, scratch that... it turns out that the only reason the above worked is because I was starting mozilla from the same dir as the javax.comm.properties file. :-)

                What really works, though, is opening the JRE plugin ControlPanel (jre/bin/ControlPanel), and adding the runtime parameter

                -Djava.class.path=...dir where javax.comm.properties lives....
                • 5. Re: can't find javax.comm.properties
                  does anybody know how to fix this problem??

                  how to add LinuxSerialParallel in java.library.path
                  • 6. javax.comm.properties / com port problem / comm.jar
                    Hi there,

                    For javax.comm the file javax.comm.properties is necessary to tell the system wich (platfrom dependend) driver to use, e.g. on Windows

                    javax.comm works like this:

                    1. javax.comm looks first at 'java.home' /lib. That is the lib directory in your local JRE. Note: If you have installed a JDK, you have to use the JRE inside the JDK.

                    2. If javax.comm.properties is not found in JRE/lib, it scans the classpath and searches for its own 'comm.jar' file. If comm.jar is found on the classpath, it tries to load javax.comm.properties from the same directory where comm.jar is located. (That is: the classpath entry of 'comm.jar' points to the directory where javax.comm.properties has to be located.)

                    That means you can put javax.comm.properties in the same directory where you put comm.jar but you have to list comm.jar explicitly on the classpath, e.g.:
                    java  -cp <your.class.path>;<path.to>/comm.jar YourProgramThatUsesComm.jar
                    Hope that helps.
                    • 7. Re: javax.comm.properties / com port problem / comm.jar
                      javax.comm.properties for WINDOWS contains com.sun.comm.win32Driver.

                      but pls pls help me by sending the same "com.sun.comm.LinuxDriver " for LINUX.
                      • 8. Re: javax.comm.properties / com port problem / comm.jar
                        If you download the Linux version of the API (http://www.sun.com/download/products.xml?id=43208d3d) , you'll get libLinuxSerialParallel.so that contains the right driver. Put that in $JAVA_HOME/jre/lib/i386, put comm.jar in $JAVA_HOME/jre/lib/ext, and set the location of the javax.comm.properties by setting -Djava.class.path=/directory/where/file/lives (in the command-line or using the control panel if using the API in an applet).
                        • 9. Re: javax.comm.properties / com port problem / comm.jar
                          Tried the following alternatives without success:

                          Putting both comm.jar and javax.comm.properties in jre/lib
                          Putting both comm.jar and javax.comm.properties in jre/lib/ext
                          Putting comm.jar in jre/lib/ext and javax.comm.properties in jre/lib

                          All above with and without adding the comm.jar to the classpath.

                          The only thing that does work is to put the javax.comm.properties in current directory.

                          This means it's got to be copied to whatever directory you are in when you run a program! Anyone know a way round it please? If not, how can we get this amended??
                          • 10. Re: can't find javax.comm.properties
                            DirkHillbrecht GOT THE ANSWER, I TRY IT AND IT WORKS. THX
                            • 11. Re: javax.comm.properties / com port problem / comm.jar
                              I installed javacomm as required:
                              If I try :
                               java -cp commtest.jar ispt/ispt
                              I get:
                              java.io.IOException: javax.comm: platform driver class name = null
                              java.lang.UnsatisfiedLinkError: isSessionActive
                              BUT if I do
                               java -cp ./commtest.jar ispt/ispt
                              everything work... go figure...
                              • 12. Re: can't find javax.comm.properties
                                I�ve developed a solution to this problem. I created a class that creates the javax.comm.properties file where the comm.jar lib looks for it. The trick is to run the method that creates the file before the lib looks for it.
                                I show you the example of my code:
                                import java.io.BufferedWriter;
                                import java.io.File;
                                import java.io.FileWriter;
                                import java.io.IOException;
                                public final class PrinterInit {
                                    public static void printerInit(){
                                        String archivoConf = 
                                            System.getProperty("java.home") + File.separator + "lib" + 
                                            File.separator + "javax.comm.properties";
                                        try {
                                            BufferedWriter out = new BufferedWriter(new FileWriter(archivoConf));
                                                "#"+ "\n" + 
                                                "# Drivers loaded by the Java Communications API standard extension"+ "\n" + 
                                                "# at initialization time "+ "\n" + 
                                                "# "+ "\n" + 
                                                "# Format: "+ "\n" + 
                                                "#   Each line must contain ONE driver definition only "+ "\n" + 
                                                "#   Each line must be of the form: "+ "\n" + 
                                                "#           driver=<ClassName> "+ "\n" + 
                                                "#       No spaces or tabs in the line. "+ "\n" +
                                                "#       ClassName must implement the interface javax.comm.CommDriver "+ "\n" + 
                                                "#           example: driver=Win32Serial"+ "\n" + 
                                                "#   "+ "\n" + 
                                                "#"+ "\n" + 
                                                "# The hash(#) character indicates comment till end of line."+ "\n" + 
                                                "#"+ "\n" + 
                                                "# Windows Serial Driver"+ "\n" + 
                                                "Driver=com.sun.comm.Win32Driver" + "\n"); 
                                        } catch (IOException e) {
                                            System.err.println("No se pudo crear el archivo:" + "javax.comm.properties");
                                            System.err.println("Ruta completa:" + archivoConf);
                                Before opening the port I call
                                This example writes de javax.comm.properties file needed for a windows implementation. You can change the value of the Driver property for the system you are using.

                                Good Luck!
                                • 13. Re: javax.comm.properties / com port problem / comm.jar
                                  Thanks MacKeeper - you got it!

                                  Simply copying the javax.comm.properties to a working directory would not make any sense to me!
                                  Since the Java Communications API is ment to be an extension to the standard classes it should be correctly loaded through the Extension Mechanism so any application using the particular JVM could make use of javax.comm.

                                  Thank you once more for saving my day ;-)

                                  • 14. Re: javax.comm.properties / com port problem / comm.jar
                                    Guys, i found a reason for this problem.
                                    It's a simly logically error in the comm.jar, i used decompiler and found that. Look here, here it is:
                                    package com.sun.comm;
                                    import java.io.*;
                                    import java.util.Properties;
                                    import java.util.StringTokenizer;
                                    public class CommProperties
                                        public CommProperties()
                                        public static String getProperty(String propName)
                                            return commProps.getProperty(propName);
                                        public static String getPropFilename()
                                            return propFilename;
                                        private static String findPropFile(String filename)
                                            if((new File(filename)).exists())
                                                return filename;
                                            for(StringTokenizer st = new StringTokenizer(System.getProperty("java.class.path"), File.pathSeparator); st.hasMoreTokens();)
                                                File p = null;
                                                File f = new File(st.nextToken());
                                                        p = new File(f.getPath() + File.separator + filename);
                                                    if(f.getParent() != null)
                                                        p = new File(f.getParent() + File.separator + filename);
                                                    return p.getPath();
                                            String defaultPath = System.getProperty("java.home") + File.separator + "lib" + File.separator + filename;
                                            if((new File(defaultPath)).exists())
                                                return defaultPath;
                                            defaultPath = System.getProperty("java.home") + File.separator + "jre" + File.separator + "lib" + File.separator + filename;
                                            if((new File(defaultPath)).exists())
                                                return defaultPath;
                                                return null;
                                        private static Properties commProps;
                                        private static String propFilename;
                                            commProps = new Properties();
                                            propFilename = null;
                                                if((propFilename = findPropFile("javax.comm.properties")) != null)
                                                    commProps.load(new BufferedInputStream(new FileInputStream(new File(propFilename))));
                                                    System.err.println("javax.comm:  Can't find javax.comm.properties!");
                                            catch(Exception e)
                                                System.err.println("javax.comm:  Error loading javax.comm.properties!");
                                    Note that if when called class constructor, it tries to find javax.comm.properties and print "Can't find javax.comm.properties!" if it's not found.
                                    But the most popular message is "javax.comm: Error loading javax.comm.properties!". Take a look at the code - such message comes up if Exception is thrown.
                                    That happens in the findPropFile method... Look, in the cycle there is a declaration p = null... And then, if f is not exist, we got NullPointerException,
                                    when checking p.exists() !!!
                                    So, if javax.comm.properties not found in the first item of classpath, you have nothing work.
                                    Stupid sun developers!

                                    You have two ways to solve problem: set the classpath so that property file is there, or to recompile that class and insert in your comm.jar. All you have
                                    to do is only change
                                                    return p.getPath();
                                                if(p!=null && p.exists())
                                                    return p.getPath();
                                    Have fun and sorry for my English....

                                    Edited by: Lobzik on Jun 19, 2008 7:19 AM
                                    1 2 Previous Next