Page 1 of 2 12 LastLast
Results 1 to 20 of 25
Like Tree2Likes

Thread: javax.comm Run Problem

  1. #1
    mr_anderson is offline Member
    Join Date
    May 2010
    Location
    Florida
    Posts
    68
    Rep Power
    0

    Default javax.comm Run Problem

    Hi
    I am using javax.comm package to write an application that sends and receives data using the serial port. My operating system is windows XP. When I run the code from NetBeans6.8 everything works perfectly but when I package it (Build it) and run it from the run prompt like this:
    java -jar "C:\RS232InternetPC\dist\RS232InternetPC.jar"

    The application fails to find any serial port although the same application works just fine when I run it from the NetBeans6.8. How can I solve this issue?
    Any ideas comments are highly appreciated.
    Best Regards.
    Anderson.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default

    Do you have all the parts where they need be? Does this version use the comm.jar file? Is it on the classpath?
    Is there a .dll needed?
    Do you get any error messages?

  3. #3
    mr_anderson is offline Member
    Join Date
    May 2010
    Location
    Florida
    Posts
    68
    Rep Power
    0

    Default

    Dear Norm
    I have placed the following three files as shown below:

    comm.jar
    win32com.dll
    javax.comm.properties

    comm.jar should be placed in:

    %JAVA_HOME%/lib

    %JAVA_HOME%/jre/lib/ext


    win32com.dll should be placed in:

    %JAVA_HOME%/bin

    %JAVA_HOME%/jre/bin

    %windir%System32


    javax.comm.properties should be placed in:

    %JAVA_HOME%/lib

    %JAVA_HOME%/jre/lib

    I am not getting any Error Messages.
    The application works just fine when I run it from netbeans but when I run it from the command prompt it doesn't recognize any port (no serials nor parallels).
    Regards.
    Attached Files Attached Files
    Last edited by mr_anderson; 08-09-2011 at 11:07 PM.

  4. #4
    mr_anderson is offline Member
    Join Date
    May 2010
    Location
    Florida
    Posts
    68
    Rep Power
    0

    Default

    I also have read online that I should set the system security manager to null --> System.setSecurityManager(null);
    I tried it but I still have the same problem

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default

    Does your code ignore any caught exceptions? I assume all catch blocks have printStackTrace calls in them.
    My serial port program gives me this when I run it on this PC that does not have a serial port:
    Open port error SerialComm.SerialConnectionException
    on port: COM1
    openGPS() returned ex: WayPointApps.GPSDevices.SerialCommException: openGPS: open port error, SerialComm.SerialConnectionException

    I have no idea where this message comes from. I haven't looked at the code in years.

    I have all the files (dll, jar and properties) in one folder and have the manifest Class-path set to:

    Class-Path: comm.jar DocumentViewerWParser.jar
    Last edited by Norm; 08-09-2011 at 11:14 PM. Reason: Added more
    mr_anderson likes this.

  6. #6
    mr_anderson is offline Member
    Join Date
    May 2010
    Location
    Florida
    Posts
    68
    Rep Power
    0

    Default

    I will double check and keep you informed about it.
    Thank you for your time.
    Regards.

  7. #7
    mr_anderson is offline Member
    Join Date
    May 2010
    Location
    Florida
    Posts
    68
    Rep Power
    0

    Default

    Dear Norm
    For test purposes I made a very simple program that just counts the available ports
    When I run it from NetBeans it runs perfectly but when I run it from command line it doens't read the available ports. Bythe way how can I/We catch any thrown exception in the code below ?

    Java Code:
    import java.util.Enumeration;
    import javax.comm.CommPortIdentifier;
    
    public class Main {
        public static void main(String[] args) {
            System.setSecurityManager(null);
            Enumeration port_list = CommPortIdentifier.getPortIdentifiers();
                while (port_list.hasMoreElements())
                {
                    CommPortIdentifier port_id = (CommPortIdentifier)port_list.nextElement();
                    if (port_id.getPortType() == CommPortIdentifier.PORT_SERIAL)
                        {
                        System.out.println("Serial port:"+ port_id.getName()+" ");
                        }
                    else if (port_id.getPortType() == CommPortIdentifier.PORT_PARALLEL)
                        {
                        System.out.println("Parallel port:" + port_id.getName());
                        }
                    else{
                      System.out.println("Other port:" + port_id.getName());
                         }
                 }
        }
    }

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default

    CommPortIdentifier.getPortIdentifiers();
    Sorry, my serial port code is as of 1998. I don't have that class.

    No idea why it works in the IDE and not in a jar. Usually the problem is in the configuration of the jar file.
    What is in the jar file's manifest file? You can open a jar file with a zip utility.
    mr_anderson likes this.

  9. #9
    mr_anderson is offline Member
    Join Date
    May 2010
    Location
    Florida
    Posts
    68
    Rep Power
    0

    Default

    Dear Norm
    I have attached the needed files (comm.jar, win32com.dll, javax.comm.properties) in this post.I opened the JAR's META-INF Folder and I got the contents of the MANIFEST.MF which are:
    Java Code:
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.7.1
    Created-By: 17.0-b17 (Sun Microsystems Inc.)
    Main-Class: javaapplication6.Main
    Class-Path: lib/comm.jar
    X-COMMENT: Main-Class will be added automatically by build
    Regards.
    Attached Files Attached Files

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default

    Is the comm.jar file in the lib folder and the lib folder in the same folder as your jar file?

  11. #11
    mr_anderson is offline Member
    Join Date
    May 2010
    Location
    Florida
    Posts
    68
    Rep Power
    0

    Default

    Yes I have checked that.
    The comm.jar is in the lib folder and the JavaApplication6.jar (my application) are in the same folder.

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default

    Your jar file should NOT be in the same folder with the comm.jar file. It needs to be in the folder that has the lib folder in it.

  13. #13
    mr_anderson is offline Member
    Join Date
    May 2010
    Location
    Florida
    Posts
    68
    Rep Power
    0

    Default

    They are not in the same folder I meant that the jar file and the lib folder are in the same folder and the lib folder has the comm.jar file inside it.
    Regards.

  14. #14
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default

    One thing that is different from my setup is that I have everything in the same folder. That shouldn't make a difference. No other ideas
    Try a test by changing to: Class-Path: comm.jar

    The folder I run the jar file from contains:
    Java Code:
    D:\Work\TestFromJar>dir
     Volume in drive D is Work
     Volume Serial Number is 1463-F5AE
    
     Directory of D:\Work\TestFromJar
    
    05/10/2010  08:00 PM    <DIR>          .
    05/10/2010  08:00 PM    <DIR>          ..
    11/15/1998  04:00 PM            28,043 comm.jar
    12/05/2001  02:34 PM            76,799 DocumentViewerWParser.jar
    12/18/2000  01:17 PM               768 FileWptsIcon.jpg
    07/28/2004  11:59 AM               412 GPS Device Communicator.lnk
    05/04/2011  02:45 PM           345,955 GPSDevComm.jar
    09/17/2005  02:21 PM           301,315 GPSDevCommOLD.jar
    09/30/2004  11:23 AM               293 GPSDeviceCommunicator.ini
    05/10/2010  08:01 PM               421 GPSDeviceCommunicator.log
    12/18/2000  01:26 PM             1,069 GPSRteIcon.jpg
    12/18/2000  01:13 PM               966 GPSWptsIcon.jpg
    11/15/1998  03:59 PM               467 javax.comm.properties
    10/28/2005  11:01 AM                32 QuesReGPSpgm.txt
    05/07/2004  09:34 AM             1,023 Readme.txt
    07/04/2006  09:12 PM    <DIR>          Waypoints
    11/15/1998  04:00 PM            27,648 win32com.dll
    05/07/2004  09:35 AM               351 _MakeGPSDevComZIP.bat
                  15 File(s)        785,562 bytes
                   3 Dir(s)   1,370,492,928 bytes free
    
    D:\Work\TestFromJar>
    Last edited by Norm; 08-10-2011 at 12:25 AM.

  15. #15
    mr_anderson is offline Member
    Join Date
    May 2010
    Location
    Florida
    Posts
    68
    Rep Power
    0

    Default

    Dear Norm
    My manifest file is generated by Netbeans IDE and here is how it looks
    Java Code:
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.7.1
    Created-By: 17.0-b17 (Sun Microsystems Inc.)
    Main-Class: javaapplication6.Main
    Class-Path: lib/comm.jar
    X-COMMENT: Main-Class will be added automatically by build
    I can see your class path is set to :
    Java Code:
    Class-Path: comm.jar DocumentViewerWParser.jar
    as compared to my class path you have two jars while mine has only 1?
    I tried to unzip my Jar file---> edit itz content and re-rar it then change the extension to jar file so that I have my new Jar file with the manifest's class path set by me but it gave me an error of "Jar corrupted".
    By the way which compiler do you use?

  16. #16
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default

    I use the JDK's javac command to compile and the jar command to build my jar files. I create the manifest file with an editor and a batch file to run the jar command with an editor. I don't use any of the IDEs.

    class path you have two jars
    Yes I have some other code in the second jar file that my GPS code uses.
    Last edited by Norm; 08-10-2011 at 01:35 AM.

  17. #17
    mr_anderson is offline Member
    Join Date
    May 2010
    Location
    Florida
    Posts
    68
    Rep Power
    0

    Default

    Did the following code run normally with you (I mean when you build it as a jar and run it from CMD) ?
    Java Code:
    import java.util.Enumeration;
    import javax.comm.CommPortIdentifier;
    
    public class Main {
        public static void main(String[] args) {
            System.setSecurityManager(null);
            Enumeration port_list = CommPortIdentifier.getPortIdentifiers();
                while (port_list.hasMoreElements())
                {
                    CommPortIdentifier port_id = (CommPortIdentifier)port_list.nextElement();
                    if (port_id.getPortType() == CommPortIdentifier.PORT_SERIAL)
                        {
                        System.out.println("Serial port:"+ port_id.getName()+" ");
                        }
                    else if (port_id.getPortType() == CommPortIdentifier.PORT_PARALLEL)
                        {
                        System.out.println("Parallel port:" + port_id.getName());
                        }
                    else{
                      System.out.println("Other port:" + port_id.getName());
                         }
                 }
        }
    }

  18. #18
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default

    I haven't done anything with your code. If the code works in your IDE, then the problem must be in the way the jar file is being built.

  19. #19
    mr_anderson is offline Member
    Join Date
    May 2010
    Location
    Florida
    Posts
    68
    Rep Power
    0

    Default

    Dear Norm
    I am thinking of rebuilding the same project using Eclipse, and if it fails I may build my jar file using the java javac commands. What do you think about that?

    Best Regards.
    Anderson.

  20. #20
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default

    I may build my jar file using the java javac commands.
    You build a jar with the jar command.
    The javac command generates .class files from .java files in a process known as compiling. The java command reads and executes the .class files.

    Here is a sample batch file I use to build a jar file:
    PHP Code:
    @Rem create the GetURLText.jar file:
    %DEV_DRIVE%
    cd %DEV_HOME%\JavaDevelopment\NormsTools\GetURLText
    jar -cmf  GetURLText.mnf  %JAVA_RUN%\GetURLText.jar  GetURLText*.class
    cd %DEV_HOME%\JavaDevelopment\
    jar -uf %JAVA_RUN%\GetURLText.jar NormsTools\IntInputField*.class NormsTools\ErrDialog*.class NormsTools\MyLabel*.class NormsTools\MakeEnterDoAction*.class NormsTools\MessageArea*.class NormsTools\ArrayUtil*.class NormsTools\ChoiceOfYesOrNo*.class NormsTools\ShowMsgBox*.class NormsTools\ShowCounters*.class
    cd %DEV_HOME%\JavaDevelopment\Misc_Projects\DownloadFilesProject
    jar -uf %JAVA_RUN%\GetURLText.jar DownloadFilesProject.html
    @Echo ---- Created %JAVA_RUN%\GetURLText.jar ---- 
    MORE

Page 1 of 2 12 LastLast

Similar Threads

  1. Add new package javax.comm
    By rjagan in forum New To Java
    Replies: 5
    Last Post: 04-12-2011, 09:07 AM
  2. import javax.comm
    By kareena in forum Threads and Synchronization
    Replies: 2
    Last Post: 09-21-2010, 03:45 PM
  3. Replies: 7
    Last Post: 07-12-2010, 04:24 PM
  4. javax/comm/SerialPortEvent
    By musiigedeo in forum Threads and Synchronization
    Replies: 9
    Last Post: 11-24-2008, 11:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •