Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

can't find javax.comm.properties

843804Oct 15 2005 — edited Sep 8 2010
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!
null

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?

Comments

843804
Hi,

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,
Dirk
843804
Hi,

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,
Dirk
843804
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.
843804
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....
843804
does anybody know how to fix this problem??

how to add LinuxSerialParallel in java.library.path
?
843804
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
com.sun.comm.Win32Driver
.

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.
Stefan.
843804
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.
843804
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).
843804
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??
843804
DirkHillbrecht GOT THE ANSWER, I TRY IT AND IT WORKS. THX
843804
I installed javacomm as required:
$JAVA_HOME/jre/lib/javax.comm.properties
$JAVA_HOME/jre/lib/ext/comm.jar
$JAVA_HOME/jre/lib/i386/libLinuxSerialParallel.so
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...
843804
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));
            
            out.write(
                "#"+ "\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"); 
            
            out.close();
        } 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
PrinterInit.printerInit();
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!
843804
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 ;-)

Cheers!
Peter,
AUSTRIA
843804
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());
            if(f.exists())
                if(f.isDirectory())
                    p = new File(f.getPath() + File.separator + filename);
                else
                if(f.getParent() != null)
                    p = new File(f.getParent() + File.separator + filename);
            if(p.exists())
                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;
        else
            return null;
    }

    private static Properties commProps;
    private static String propFilename;

    static 
    {
        commProps = new Properties();
        propFilename = null;
        try
        {
            if((propFilename = findPropFile("javax.comm.properties")) != null)
                commProps.load(new BufferedInputStream(new FileInputStream(new File(propFilename))));
            else
                System.err.println("javax.comm:  Can't find javax.comm.properties!");
        }
        catch(Exception e)
        {
            System.err.println("javax.comm:  Error loading javax.comm.properties!");
            System.err.println(e.getMessage());
        }
    }
}
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
            if(p.exists())
                return p.getPath();
to
            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
843804
Hello, I read through this posting in this thread.
As we have a special situation with binary compiled Java bytecode, adding the comm.jar on the first position / token of the
CLASSPATH
is not possible.
Recompilling the PropertyFinder neither, because of missing source-code and license agreement.

What always worked so far was to put the property file in the
 <JRE>/lib
directory and the comm.jar in the
 <JRE>/lib/ext
directory.
The dll (running windows) is loacted in a directory where
PATH
points to.

Regards, Stephan
1 - 15
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Oct 6 2010
Added on Oct 15 2005
15 comments
19,256 views